﻿using System;
using System.IO;
using System.Data;
using System.Text;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Resources;
using System.Globalization;

using CE.Mail;
using CE.User;
using CE.Global;
using CE.Security;
using CE.InputOut;
using CE.Database;
using CE.CarInsurance;
using CXDecryption;

public partial class carinsurance_offline_callme_newlead_quotes : System.Web.UI.Page
{
    CarUserAccount _account = null;
    CarUserAccountDB _accountdb = null;
    CarUserProfile _profile = null;
    CarUserProfileDB _profiledb = null;
    CarUserContact _contact = null;
    CarUserContactDB _contactdb = null;
    int _currentRow = 0;
    private DateTime dateTimeNow = CE.Global.General.GetUTCDateTime();

    protected override void InitializeCulture()
    {
        String selectedCulture = CE.Global.General.SetCulture();
        base.InitializeCulture();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null)
        {
            Response.Redirect("~/SiteUserSecureLogin.aspx");
        }

        if (!IsPostBack)
        {

            lblResetUrl.Text = Request.Url.ToString();
            ResetAll();
            DateTime time = dateTimeNow;
            lblStartDateTime.Text = time.ToString("dd/MMM/yyyy hh:mm:ss tt"); //Don't use HTML tag inside text
            txtAgentId.Text = Session[General.UserId].ToString();
            LoadAgentList();

            txtTargetDate.Text = dateTimeNow.ToString("dd-MMM-yyyy");
            cexTargetDate.StartDate = dateTimeNow;
            cexTargetDate.EndDate = GetCallBackDateLimit(15); //dateTimeNow.AddDays(GetNoOfCallBackDay());

            ddlCIMainCallStatus.Items.Clear();
            ddlCICallStatus.Items.Clear();
            rdoCallFinish.Checked = true;
            rdoCallFinish_CheckedChanged(sender, e);

            GetCarBody();
            // lee @24/03/2015 exist in rdoCallFinish_CheckedChanged(sender, e);
            //if (ddlCIMainCallStatus.Items.Count > 0)
            //{
            //    ddlCIMainCallStatus.SelectedIndex = 0;
            //    ddlCIMainCallStatus_SelectedIndexChanged(sender, e);
            //}
            if (Request.QueryString["calltype"] != null)
            {
                txtCallTypeId.Text = Request.QueryString["calltype"].ToString();
                lblRedirectCallTypeId.Text = Request.QueryString["calltype"].ToString();
                ShowCallTypeDesc();
            }
            else
            {
                Response.Redirect("~/SiteUserHome.aspx");
            }

            if (Request.QueryString["carid"] != null)
            {
                txtCarId.Text = Request.QueryString["carid"].ToString();
                lblRedirectCarId.Text = Request.QueryString["carid"].ToString();
            }
            if (Request.QueryString["callmeid"] != null)
            {
                txtCallMeId.Text = Request.QueryString["callmeid"].ToString();
            }

            if (Request.QueryString["proid"] != null)
            {
                hidPromotionId.Value = Request.QueryString["proid"].ToString();
            }

            if (Request.QueryString["new"] != null)
            {
                txtNewQuote.Text = Request.QueryString["new"].ToString();
            }
            else
            {
                txtNewQuote.Text = string.Empty;
            }

            if (Request.Params["leadid"] != null && Request.Params["calltype"] != null)
            {
                txtAgentLeadId.Text = Request.QueryString["leadid"].ToString();
                txtCallTypeId.Text = Request.QueryString["calltype"].ToString();
                lblRedirectAgentLeadId.Text = Request.QueryString["leadid"].ToString();
                Int64 _leadId = 0;
                Int16 _callType = 0;
                Int64 _carId = 0;
                Int64 _custId = 0;
                if (Int64.TryParse(Request.Params["leadid"].ToString(), out _leadId)
                    && Int16.TryParse(Request.Params["calltype"].ToString(), out _callType)
                    && Int64.TryParse(Request.Params["carid"].ToString(), out _carId)
                    && Int64.TryParse(Request.Params["custid"].ToString(), out _custId))
                {
                    txtCustomerId.Text = _custId.ToString();
                    lblRedirectCustomerId.Text = _custId.ToString();

                    if (_carId == 0 && _custId == 0)
                    {
                        txtAgentLeadId.Text = _leadId.ToString();
                        txtCallTypeId.Text = _callType.ToString();
                    }
                    else if (!ShowScreen(_leadId, _callType, _carId, _custId))
                    {
                        lblCallSessionName.Text = Resources.General.NORECORDFOUND;
                        ResetAll();
                    }
                }
                else
                {
                    Response.Redirect("~/SiteUserHome.aspx");
                }
            }
            else if (!ShowScreen())
            {
                lblCallSessionName.Text = Resources.General.NORECORDFOUND;
                lblCallSessionName.Text += "<br/><br/>INVALID. NOT FOUND! CHECK CX IT TEAM.";
                pnlQuotes.Visible = false;
                divCallStatus.Visible = false;
                ResetAll();
            }


            LoadInsuranceType();
            LoadGarageType();
            //LoadCarYear();
            LoadOccupation();
            LoadDOB();
            LoadCommanceDate();
            LoadCurrentInsurer();
            LoadCallMeUser();
            ddlInsuranceType.Text = "10";
            ddlInsuranceType_SelectedIndexChanged(null, null);

            if (txtNewQuote.Text != "1")
            {
                if (txtCarId.Text != string.Empty && Convert.ToInt64(txtCarId.Text) > 0)
                {
                    DataSet _dsCar = new DataSet();
                    _dsCar = GetCarDetails(Convert.ToInt64(txtCarId.Text));
                    if (_dsCar != null && _dsCar.Tables.Count > 0 && _dsCar.Tables[0].Rows.Count > 0)
                    {
                        txtCustomerId.Text = _dsCar.Tables[0].Rows[0]["RefCEUserId"].ToString();
                        lblRedirectCustomerId.Text = txtCustomerId.Text;
                        txtCECarPolicyId.Text = _dsCar.Tables[0].Rows[0]["CECarPolicyID"].ToString();
                        if (txtCarId.Text != string.Empty && Convert.ToInt64(txtCarId.Text) > 0
                            && txtCustomerId.Text != string.Empty && Convert.ToInt64(txtCustomerId.Text) > 0
                            && txtCECarPolicyId.Text != string.Empty && Convert.ToInt64(txtCECarPolicyId.Text) > 0)
                        {

                            if (Request.Params["renew"] != null && Request.Params["refno"] != null)
                            {
                                //Any case for renewal

                                divLastYearRefNo.Visible = true;
                                lblLastYearRefNo.Text = Request.Params["refno"].ToString();
                                lblLastYearCarID.Text = General.GetCarId(lblLastYearRefNo.Text);
                                lblCallTypeDesc.Text += " - " + Resources.Proposal.Renewal; //Renewal";
                                //First Time - create new ID but load from Old Car ID
                                lblRenewalStatus.Text = Request.Params["renew"].ToString();

                                if (Request.Params["renew"].ToString() == "1")
                                {
                                    ShowCarAndPolicyDetail(Convert.ToInt64(txtCarId.Text), Convert.ToInt64(txtCECarPolicyId.Text), Convert.ToInt64(txtCustomerId.Text), 1);
                                    txtCarId.Text = "0"; //TO CREATE NEW CAR ID
                                    txtCECarPolicyId.Text = "0"; //TO CREATE NEW CAR ID
                                    btnNonGGQuotation.Visible = false;
                                }
                                //Second time load
                                else
                                {
                                    ShowCarAndPolicyDetail(Convert.ToInt64(txtCarId.Text), Convert.ToInt64(txtCECarPolicyId.Text), Convert.ToInt64(txtCustomerId.Text), 0);
                                    btnNonGGQuotation.Visible = true;
                                }
                            }
                            else
                            {
                                divLastYearRefNo.Visible = false;
                                lblLastYearRefNo.Text = string.Empty;
                                ShowCarAndPolicyDetail(Convert.ToInt64(txtCarId.Text), Convert.ToInt64(txtCECarPolicyId.Text), Convert.ToInt64(txtCustomerId.Text), 0);
                            }
                        }

                        if (Request.QueryString["ismobile"] != null)
                        {
                            //First time from Mobile
                            ddlGender.BorderColor = System.Drawing.Color.Red;
                            ddlModelBodyCCDoor.BorderColor = System.Drawing.Color.Red;
                            ddlCoverageComDate.BorderColor = System.Drawing.Color.Red;
                            ddlCurrentInsurer.BorderColor = System.Drawing.Color.Red;
                            ddlNamedDrivers.BorderColor = System.Drawing.Color.Red;
                            ddlModification.BorderColor = System.Drawing.Color.Red;
                            ddlDeduct.BorderColor = System.Drawing.Color.Red;
                            ddlProvinceRegistration.BorderColor = System.Drawing.Color.Red;
                            ddlAnyClaim.BorderColor = System.Drawing.Color.Red;
                            ddlNCB.BorderColor = System.Drawing.Color.Red;
                            ClientScript.RegisterStartupScript(this.GetType(), "firstmobile", "alert('" + Resources.General.VerifyData + "');", true);
                        }
                    }
                }
                else if (txtCustomerId.Text != string.Empty && Convert.ToInt64(txtCustomerId.Text) > 0)
                {
                    _account = new CarUserAccount();
                    _accountdb = new CarUserAccountDB();
                    _account = _accountdb.GetAccount(Convert.ToInt64(txtCustomerId.Text));
                    if (_account != null)
                    {
                        ShowCustomerDetail(_account);
                    }
                }
            }
            else
            {
                txtCarId.Text = string.Empty;
            }

            if (txtAgentLeadId.Text != string.Empty && txtCallTypeId.Text != string.Empty)
            {
                ShowCallStatus(Convert.ToInt64(txtAgentLeadId.Text), Convert.ToInt32(txtCallTypeId.Text));
            }

            if (Request.QueryString["mobile"] != null)
            {
                txtMobileNo.Text = Request.QueryString["mobile"].ToString();
            }

            if (Request.QueryString["email"] != null)
            {
                txtEmailAddress.Text = Request.QueryString["email"].ToString();
                txtEmailAddress.ReadOnly = false;
                txtEmailAddress.Enabled = true;
            }

            if (Request.QueryString["name"] != null)
            {
                txtLastName.Text = Request.QueryString["name"].ToString();
            }
        }
        else
        {
            lblCallStatusMessage.Text = "";
            lblLastCallStatusMessage.Text = "";
        }
    }

    private void ShowCallTypeDesc()
    {
        if (txtCallTypeId.Text == "100")
        {
            
            lblPageName.Text = Resources.General.FirstFollowUpCall;
            lblLastCallStatusCaption.Text = Resources.General.FirstFollowUpCall + " - " + Resources.General.LastCallStatus;
        }
        else if (txtCallTypeId.Text == "101")
        {
            lblPageName.Text = Resources.General.CallMeRequest;
            lblLastCallStatusCaption.Text = Resources.General.CallMeRequest + " - " + Resources.General.LastCallStatus;
        }
        else if (txtCallTypeId.Text == "102")
        {
            lblPageName.Text = Resources.General.CallMeBack;
            lblLastCallStatusCaption.Text = Resources.General.CallMeBack + " - " + Resources.General.LastCallStatus;
        }
        else if (txtCallTypeId.Text == "103") //102
        {
            lblPageName.Text = Resources.General.CallDirect;
            lblLastCallStatusCaption.Text = Resources.General.CallDirect + " - " + Resources.General.LastCallStatus;
        }
    }

    #region Other
  
    private void GetCarBody()
    {
        try
        {
            MyDatabase _db = new MyDatabase();
            DataTable _dt = new DataTable();
            string _splStatement = "select distinct BodyStyleDescription from tblCarVehicle where BodyStyleDescription is not null order by BodyStyleDescription";

            _dt = _db.GetDataTable(_splStatement);
            ddlOtherCarBody.Items.Clear();
            if (_dt != null && _dt.Rows.Count > 0)
            {
                ddlOtherCarBody.DataSource = _dt;
                ddlOtherCarBody.DataTextField = "BodyStyleDescription";
                ddlOtherCarBody.DataValueField = "BodyStyleDescription";
                ddlOtherCarBody.DataBind();
            }
            ddlOtherCarBody.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        }
        catch (Exception)
        {
        }
    }
    #endregion

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (CheckClaimValue() == true)
        {
            Page.Validate("newleads");
            if (Page.IsValid)
            {
                try
                {
                    DateTime _dtDOB = new DateTime(Convert.ToInt32(ddlDOBYear.Text), Convert.ToInt32(ddlDOBMonth.Text), Convert.ToInt32(ddlDOBDay.Text));
                }
                catch
                {
                    lblMessage.Text = Resources.Proposal.DOB + " ไม่ถูกต้อง";
                    return;
                }

                Int64 _userId = 0;

                if (!Int64.TryParse(txtCustomerId.Text, out _userId))
                {
                    _userId = 0;
                }

                if (_userId == 0)
                {
                    CarUserAccount _userAccount = GetCustomerAccount();

                    if (_userAccount != null && _userAccount.CEID > 0)
                    {
                        //txtCustomerId.Text = _userAccount.CEID.ToString();
                        //lblRedirectCustomerId.Text = _userAccount.CEID.ToString();
                        //_userId = _userAccount.CEID;

                        lblMessage.Text = "Email นี้มีในระบบแล้ว ไม่สามารถสร้างลูกค้าใหม่ได้";
                        return;
                    }
                }

                _userId = UpdateProfile(_userId);

                if (_userId > 0)
                {
                    

                    if (Save(_userId))
                    {
                        btnNonGGQuotation.Visible = true;
                        lblMessage.Text = "Saved successfully!";

                       
                        CalculatePremiumCRM();

                        uplResults.Update();
                    }
                    else
                    {
                        lblMessage.Text = "Saving did NOT succeed!";
                    }
                }
                else
                {
                    lblMessage.Text = "Please fill all require fields completly and correctly.";
                }
            }
        }
        else
        {
            lblMessage.Text = "Please fill claim value correctly.";
        }

    }

    protected void btnReset_Click(object sender, EventArgs e)
    {
        Response.Redirect(lblResetUrl.Text.ToString());
    }

    protected void btnNonGGQuotation_Click(object sender, EventArgs e)
    {
        btnBack_Click(sender, e);
    }

    protected void btnBack_Click(object sender, EventArgs e)
    {
        string _strParameters = "leadid=" + txtAgentLeadId.Text + "&calltype=" + txtCallTypeId.Text.Trim();
        _strParameters += "&custid=" + txtCustomerId.Text.Trim() + "&carid=" + txtCarId.Text.Trim();
        Response.Redirect("ViewCINoMatchFound.aspx?" + _strParameters.ToString());
    }

    protected void ddlInsuranceType_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            LoadCarYear();
            if (ddlInsuranceType.Text == "10")
            {
               

                ddlGarageType.Enabled = true;
                rowGarageType.Visible = true;
                ddlCTPL.Enabled = false;
                ddlModification.Enabled = true;
                txtAccModAmount.Enabled = false;
                ddlDeduct.Enabled = true;
                ddlProvinceRegistration.Enabled = true;
                ddlAnyClaim.Enabled = true;
                ddlNCB.Enabled = true;
                ddlNamedDrivers.Enabled = true;
                ddlDriver1DOBDay.Enabled = false;
                ddlDriver1DOBMonth.Enabled = false;
                ddlDriver1DOBYear.Enabled = false;
                ddlDriver2DOBDay.Enabled = false;
                ddlDriver2DOBMonth.Enabled = false;
                ddlDriver2DOBYear.Enabled = false;

                ddlGarageType.SelectedIndex = 0;
                ddlCarYear.SelectedIndex = 0;
                ddlCarYear_SelectedIndexChanged(null, null);
                ddlCTPL.SelectedIndex = 0;
                ddlModification.SelectedIndex = 0;
                ddlModification_SelectedIndexChanged(null, null);
                txtAccModAmount.Text = "";
                ddlDeduct.SelectedIndex = 0;
                ddlProvinceRegistration.SelectedIndex = 0;
                ddlAnyClaim.SelectedIndex = 0;
                ddlNCB.SelectedIndex = 0;
                ddlNamedDrivers.SelectedIndex = 0;
                ddlNamedDrivers_SelectedIndexChanged(null, null);
                ddlDriver1DOBDay.SelectedIndex = 0;
                ddlDriver1DOBMonth.SelectedIndex = 0;
                ddlDriver1DOBYear.SelectedIndex = 0;
                ddlDriver2DOBDay.SelectedIndex = 0;
                ddlDriver2DOBMonth.SelectedIndex = 0;
                ddlDriver2DOBYear.SelectedIndex = 0;
            }
            else if (ddlInsuranceType.Text == "11")
            {
               
                ddlGarageType.Enabled = true;
                rowGarageType.Visible = true;
                ddlCTPL.Enabled = false;
                ddlModification.Enabled = false;
                txtAccModAmount.Enabled = false;
                ddlDeduct.Enabled = false;
                ddlProvinceRegistration.Enabled = false;
                ddlAnyClaim.Enabled = false;
                ddlNCB.Enabled = false;
                ddlNamedDrivers.Enabled = false;
                ddlDriver1DOBDay.Enabled = false;
                ddlDriver1DOBMonth.Enabled = false;
                ddlDriver1DOBYear.Enabled = false;
                ddlDriver2DOBDay.Enabled = false;
                ddlDriver2DOBMonth.Enabled = false;
                ddlDriver2DOBYear.Enabled = false;

                ddlGarageType.SelectedIndex = 0;
                ddlCarYear.SelectedIndex = 0;
                ddlCarYear_SelectedIndexChanged(null, null);
                ddlCTPL.SelectedIndex = 0;
                ddlModification.SelectedIndex = 0;
                ddlModification_SelectedIndexChanged(null, null);
                txtAccModAmount.Text = "";
                ddlDeduct.SelectedIndex = 0;
                ddlProvinceRegistration.SelectedIndex = 0;
                ddlAnyClaim.SelectedIndex = 0;
                ddlNCB.SelectedIndex = 0;
                ddlNamedDrivers.SelectedIndex = 0;
                ddlNamedDrivers_SelectedIndexChanged(null, null);
                ddlDriver1DOBDay.SelectedIndex = 0;
                ddlDriver1DOBMonth.SelectedIndex = 0;
                ddlDriver1DOBYear.SelectedIndex = 0;
                ddlDriver2DOBDay.SelectedIndex = 0;
                ddlDriver2DOBMonth.SelectedIndex = 0;
                ddlDriver2DOBYear.SelectedIndex = 0;
            }
            else if (ddlInsuranceType.Text == "21")
            {
               

                ddlGarageType.Enabled = true;
                rowGarageType.Visible = true;
                ddlCTPL.Enabled = false;
                ddlModification.Enabled = false;
                txtAccModAmount.Enabled = false;
                ddlDeduct.Enabled = true;
                ddlProvinceRegistration.Enabled = false;
                ddlAnyClaim.Enabled = false;
                ddlNCB.Enabled = false;
                ddlNamedDrivers.Enabled = false;
                ddlDriver1DOBDay.Enabled = false;
                ddlDriver1DOBMonth.Enabled = false;
                ddlDriver1DOBYear.Enabled = false;
                ddlDriver2DOBDay.Enabled = false;
                ddlDriver2DOBMonth.Enabled = false;
                ddlDriver2DOBYear.Enabled = false;

                ddlGarageType.SelectedIndex = 0;
                ddlCarYear.SelectedIndex = 0;
                ddlCarYear_SelectedIndexChanged(null, null);
                ddlCTPL.SelectedIndex = 0;
                ddlModification.SelectedIndex = 0;
                ddlModification_SelectedIndexChanged(null, null);
                txtAccModAmount.Text = "";
                ddlDeduct.SelectedIndex = 0;
                ddlProvinceRegistration.SelectedIndex = 0;
                ddlAnyClaim.SelectedIndex = 0;
                ddlNCB.SelectedIndex = 0;
                ddlNamedDrivers.SelectedIndex = 0;
                ddlNamedDrivers_SelectedIndexChanged(null, null);
                ddlDriver1DOBDay.SelectedIndex = 0;
                ddlDriver1DOBMonth.SelectedIndex = 0;
                ddlDriver1DOBYear.SelectedIndex = 0;
                ddlDriver2DOBDay.SelectedIndex = 0;
                ddlDriver2DOBMonth.SelectedIndex = 0;
                ddlDriver2DOBYear.SelectedIndex = 0;
            }
            else if (ddlInsuranceType.Text == "31")
            {
              

                ddlGarageType.Enabled = true;
                rowGarageType.Visible = true;
                ddlCTPL.Enabled = false;
                ddlModification.Enabled = false;
                txtAccModAmount.Enabled = false;
                ddlDeduct.Enabled = true;
                ddlProvinceRegistration.Enabled = false;
                ddlAnyClaim.Enabled = false;
                ddlNCB.Enabled = false;
                ddlNamedDrivers.Enabled = false;
                ddlDriver1DOBDay.Enabled = false;
                ddlDriver1DOBMonth.Enabled = false;
                ddlDriver1DOBYear.Enabled = false;
                ddlDriver2DOBDay.Enabled = false;
                ddlDriver2DOBMonth.Enabled = false;
                ddlDriver2DOBYear.Enabled = false;

                ddlGarageType.SelectedIndex = 0;
                ddlCarYear.SelectedIndex = 0;
                ddlCarYear_SelectedIndexChanged(null, null);
                ddlCTPL.SelectedIndex = 0;
                ddlModification.SelectedIndex = 0;
                ddlModification_SelectedIndexChanged(null, null);
                txtAccModAmount.Text = "";
                ddlDeduct.SelectedIndex = 0;
                ddlProvinceRegistration.SelectedIndex = 0;
                ddlAnyClaim.SelectedIndex = 0;
                ddlNCB.SelectedIndex = 0;
                ddlNamedDrivers.SelectedIndex = 0;
                ddlNamedDrivers_SelectedIndexChanged(null, null);
                ddlDriver1DOBDay.SelectedIndex = 0;
                ddlDriver1DOBMonth.SelectedIndex = 0;
                ddlDriver1DOBYear.SelectedIndex = 0;
                ddlDriver2DOBDay.SelectedIndex = 0;
                ddlDriver2DOBMonth.SelectedIndex = 0;
                ddlDriver2DOBYear.SelectedIndex = 0;
            }
            else if (ddlInsuranceType.Text == "30")
            {
               

                ddlGarageType.Enabled = false;
                rowGarageType.Visible = false;
                ddlCTPL.Enabled = true;
                ddlModification.Enabled = false;
                txtAccModAmount.Enabled = false;
                ddlDeduct.Enabled = true;
                ddlProvinceRegistration.Enabled = false;
                ddlAnyClaim.Enabled = false;
                ddlNCB.Enabled = false;
                ddlNamedDrivers.Enabled = false;
                ddlDriver1DOBDay.Enabled = false;
                ddlDriver1DOBMonth.Enabled = false;
                ddlDriver1DOBYear.Enabled = false;
                ddlDriver2DOBDay.Enabled = false;
                ddlDriver2DOBMonth.Enabled = false;
                ddlDriver2DOBYear.Enabled = false;

                ddlGarageType.SelectedIndex = 0;
                ddlCarYear.SelectedIndex = 0;
                ddlCarYear_SelectedIndexChanged(null, null);
                ddlCTPL.SelectedIndex = 0;
                ddlModification.SelectedIndex = 0;
                ddlModification_SelectedIndexChanged(null, null);
                txtAccModAmount.Text = "";
                ddlDeduct.SelectedIndex = 0;
                ddlProvinceRegistration.SelectedIndex = 0;
                ddlAnyClaim.SelectedIndex = 0;
                ddlNCB.SelectedIndex = 0;
                ddlNamedDrivers.SelectedIndex = 0;
                ddlNamedDrivers_SelectedIndexChanged(null, null);
                ddlDriver1DOBDay.SelectedIndex = 0;
                ddlDriver1DOBMonth.SelectedIndex = 0;
                ddlDriver1DOBYear.SelectedIndex = 0;
                ddlDriver2DOBDay.SelectedIndex = 0;
                ddlDriver2DOBMonth.SelectedIndex = 0;
                ddlDriver2DOBYear.SelectedIndex = 0;
            }
            
            ValidateControlEnable();
            setControlVisible();
        }
        catch
        {

        }
    }

    

    protected void ddlCarYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlCarYear.Text == "-1")
        {
            ClearAllList();
        }
        else
        {
            GetCarMakeList(ddlCarYear.Text, ddlCarMake);
            if (ddlCarMake.Items.Count > 0)
            {
                ddlCarMake.SelectedIndex = 0;
                ddlCarMake_SelectedIndexChanged(sender, e);
            }
        }
    }

    protected void ddlCarMake_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlCarMake.Text == "-1")
        {
            ddlModelBodyCCDoor.Items.Clear();
            ddlModelBodyCCDoor.Items.Add(new ListItem(Resources.CarInsurance.Select, "-1"));
            //txtSumInsured.Text = "0";
            //lblSumInsured.Text = "0";
            //txtGroupNo.Text = "0";
        }
        else
        {
            if (ddlModelBodyCCDoor.Items.Count > 0)
                ddlModelBodyCCDoor.SelectedIndex = 0;
            GetCarModelDescList(ddlCarMake.Text, ddlCarYear.Text, ddlModelBodyCCDoor);
            //if (ddlModelBodyCCDoor.Items.Count > 0)
            //{
            //    ddlModelBodyCCDoor.SelectedIndex = 0;
            //    ddlModelBodyCCDoor_SelectedIndexChanged(sender, e);
            //}
        }
    }

    //OnSelectedIndexChanged="ddlModelBodyCCDoor_SelectedIndexChanged"
    //protected void ddlModelBodyCCDoor_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    if (ddlCarYear.SelectedIndex >= 0 && ddlCarMake.SelectedIndex >= 0 & ddlModelBodyCCDoor.SelectedIndex > 0)
    //    {
    //        string[] _tempDesc = ddlModelBodyCCDoor.Text.Split(' ');
    //        string _model = "";
    //        string _body = "";
    //        string _cc = "";
    //        string _door = "";
    //        if (_tempDesc.Length == 5)
    //        {
    //            _model = _tempDesc[0];
    //            _body = _tempDesc[1];
    //            _cc = _tempDesc[2].Substring(0, _tempDesc[2].Length - 2);
    //            _door = _tempDesc[3];
    //        }
    //        else if (_tempDesc.Length == 6)
    //        {
    //            _model = _tempDesc[0] + " " + _tempDesc[1];
    //            _body = _tempDesc[2];
    //            _cc = _tempDesc[3].Substring(0, _tempDesc[3].Length - 2);
    //            _door = _tempDesc[4];
    //        }
    //        else if (_tempDesc.Length == 7)
    //        {
    //            _model = _tempDesc[0] + " " + _tempDesc[1] + " " + _tempDesc[2];
    //            _body = _tempDesc[3];
    //            _cc = _tempDesc[4].Substring(0, _tempDesc[4].Length - 2);
    //            _door = _tempDesc[5];
    //        }
    //        lblModelDesc.Text = "model : " + _model + ", body: " + _body + ", cc: " + _cc + ", door: " + _door;
    //        GetCarModelSumInsuredAmountAndVehicleType(ddlCarMake.Text, _model, _body, _cc, _door, ddlCarYear.Text, txtSumInsured, lblSumInsured, lblCarVehicleType);
    //        txtNewSumInsured.Text = txtSumInsured.Text;
    //        if (ddlModification.Text == "1")
    //        {
    //            if (txtAccModAmount.Text.Length > 0)
    //            {
    //                int _sumInsured = Convert.ToInt32(txtSumInsured.Text);
    //                int _tmpAmount = 0;
    //                if (Int32.TryParse(txtAccModAmount.Text, out _tmpAmount))
    //                {
    //                    _sumInsured += _tmpAmount;
    //                    txtNewSumInsured.Text = _sumInsured.ToString();
    //                    lblSumInsured.Text = Convert.ToInt32(txtNewSumInsured.Text).ToString("#,000");
    //                }
    //                else
    //                {
    //                    txtNewSumInsured.Text = _sumInsured.ToString();
    //                    txtAccModAmount.Text = "";
    //                }
    //            }
    //        }
    //        txtGroupNo.Text = "0";
    //        //if (ddlModelBodyCCDoor.Text != "-2")
    //        //{
    //        //    GetCarModelGroupNo(ddlCarMake.Text, _model, _body, _cc, _door, txtGroupNo);
    //        //}
    //        //else
    //        //{
    //        //    txtGroupNo.Text = "0";
    //        //}
    //    }
    //    else
    //    {
    //        lblModelDesc.Text = "model : , body: , cc: , door: ";
    //        txtSumInsured.Text = "0";
    //        lblSumInsured.Text = "0";
    //        txtNewSumInsured.Text = "0";
    //        txtGroupNo.Text = "0";
    //    }
    //}

    protected void ddlModification_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlModification.Text == "1")
        {
           
            txtAccModAmount.Enabled = true;
            rfvAccModAmount.Enabled = true;
            revAccModAmount.Enabled = true;
        }
        else
        {
            
            txtAccModAmount.Enabled = false;
            rfvAccModAmount.Enabled = false;
            revAccModAmount.Enabled = false;
        }
        setControlVisible();
    }

    protected void ddlAnyClaim_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlAnyClaim.Text == "1")
        {
            ddlNCB.Items.Clear();
            ddlNCB.Items.Add(new ListItem("No NCD", "0"));
        }
        else
        {
            ddlNCB.Items.Clear();
            ddlNCB.Items.Add(new ListItem(Resources.General.Select, "-1"));
            ddlNCB.Items.Add(new ListItem("0 %", "0"));
            ddlNCB.Items.Add(new ListItem("20 %", "20"));
            ddlNCB.Items.Add(new ListItem("30 %", "30"));
            ddlNCB.Items.Add(new ListItem("40 %", "40"));
            ddlNCB.Items.Add(new ListItem("50 %", "50"));
        }
    }

    protected void ddlNamedDrivers_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlNamedDrivers.Text == "1")
        {
            
            ddlDriver1DOBDay.Enabled = true;
            ddlDriver1DOBMonth.Enabled = true;
            ddlDriver1DOBYear.Enabled = true;
            ddlDriver2DOBDay.Enabled = false;
            ddlDriver2DOBMonth.Enabled = false;
            ddlDriver2DOBYear.Enabled = false;

            rfvDriver1DOBDay.Enabled = true;
            rfvDriver1DOBMonth.Enabled = true;
            rfvDriver1DOBYear.Enabled = true;
            rfvDriver2DOBDay.Enabled = false;
            rfvDriver2DOBMonth.Enabled = false;
            rfvDriver2DOBYear.Enabled = false;
        }
        else if (ddlNamedDrivers.Text == "2")
        {
           
            ddlDriver1DOBDay.Enabled = true;
            ddlDriver1DOBMonth.Enabled = true;
            ddlDriver1DOBYear.Enabled = true;
            ddlDriver2DOBDay.Enabled = true;
            ddlDriver2DOBMonth.Enabled = true;
            ddlDriver2DOBYear.Enabled = true;

            rfvDriver1DOBDay.Enabled = true;
            rfvDriver1DOBMonth.Enabled = true;
            rfvDriver1DOBYear.Enabled = true;
            rfvDriver2DOBDay.Enabled = true;
            rfvDriver2DOBMonth.Enabled = true;
            rfvDriver2DOBYear.Enabled = true;
        }
        else
        {
           
            ddlDriver1DOBDay.Enabled = false;
            ddlDriver1DOBMonth.Enabled = false;
            ddlDriver1DOBYear.Enabled = false;
            ddlDriver2DOBDay.Enabled = false;
            ddlDriver2DOBMonth.Enabled = false;
            ddlDriver2DOBYear.Enabled = false;

            rfvDriver1DOBDay.Enabled = false;
            rfvDriver1DOBMonth.Enabled = false;
            rfvDriver1DOBYear.Enabled = false;
            rfvDriver2DOBDay.Enabled = false;
            rfvDriver2DOBMonth.Enabled = false;
            rfvDriver2DOBYear.Enabled = false;
        }
        setControlVisible();
    }

    protected void ResetAll()
    {
        
        txtCarId.Text = "";
        txtCECarPolicyId.Text = "";

        
    }

    private void ClearAllList()
    {
        ddlCarMake.Items.Clear();
        ddlCarMake.Items.Add(new ListItem(Resources.CarInsurance.Select, "-1"));
        ddlModelBodyCCDoor.Items.Clear();
        ddlModelBodyCCDoor.Items.Add(new ListItem(Resources.CarInsurance.Select, "-1"));
        //txtSumInsured.Text = "0";
        //lblSumInsured.Text = "0";
        //txtGroupNo.Text = "0";
    }

    private void LoadAgentList()
    {
        try
        {
            MyDatabase _db = new MyDatabase();
            DataTable _dt = new DataTable("tblList");
            string _spName = "sprocCXCRMGetAgentList";

            _dt = _db.GetDataTable(_spName);
            ddlCBAgentList.Items.Clear();
            if (_dt != null && _dt.Rows.Count > 0)
            {
                ddlCBAgentList.DataSource = _dt;
                ddlCBAgentList.DataTextField = "FULLNAME";
                ddlCBAgentList.DataValueField = "CEID";
                ddlCBAgentList.DataBind();
                ddlCBAgentList.SelectedIndex = ddlCBAgentList.Items.IndexOf(ddlCBAgentList.Items.FindByValue(Session[General.UserId].ToString()));
            }
        }
        catch (Exception Ex)
        {

        }
    }

    public void ValidateControlEnable()
    {

        if (ddlInsuranceType.Text == "10")
        {
            rfvGarageType.Enabled = true;
            rfvCarYear.Enabled = true;
            rfvCarMake.Enabled = true;
            rfvModelBodyCCDoor.Enabled = true;
            rfvCTPL.Enabled = false;
            rfvModification.Enabled = true;
            rfvAccModAmount.Enabled = false;
            revAccModAmount.Enabled = false;
            if (ddlModification.Text == "1")
            {
                rfvAccModAmount.Enabled = true;
                revAccModAmount.Enabled = true;
            }
            rfvProvinceRegistration.Enabled = true;
            rfvAnyClaim.Enabled = true;
            rfvNCB.Enabled = true;
            if (ddlNamedDrivers.Text == "0")
            {
                rfvDriver1DOBDay.Enabled = false;
                rfvDriver1DOBMonth.Enabled = false;
                rfvDriver1DOBYear.Enabled = false;
                rfvDriver2DOBDay.Enabled = false;
                rfvDriver2DOBMonth.Enabled = false;
                rfvDriver2DOBYear.Enabled = false;
            }
            else if (ddlNamedDrivers.Text == "1")
            {
                rfvDriver1DOBDay.Enabled = true;
                rfvDriver1DOBMonth.Enabled = true;
                rfvDriver1DOBYear.Enabled = true;
                rfvDriver2DOBDay.Enabled = false;
                rfvDriver2DOBMonth.Enabled = false;
                rfvDriver2DOBYear.Enabled = false;
            }
            else if (ddlNamedDrivers.Text == "2")
            {
                rfvDriver1DOBDay.Enabled = true;
                rfvDriver1DOBMonth.Enabled = true;
                rfvDriver1DOBYear.Enabled = true;
                rfvDriver2DOBDay.Enabled = true;
                rfvDriver2DOBMonth.Enabled = true;
                rfvDriver2DOBYear.Enabled = true;
            }
            rfvCoverageComDate.Enabled = true;
            rfvCurrentInsurer.Enabled = true;
            rfvFirstName.Enabled = true;
            revFirstName.Enabled = true;
            rfvLastName.Enabled = true;
            revLastName.Enabled = true;
            rfvEmailAddress.Enabled = true;
            revEmailAddress.Enabled = true;
            rfvGender.Enabled = true;
            rfvDOBDay.Enabled = true;
            rfvDOBMonth.Enabled = true;
            rfvDOBYear.Enabled = true;
            rfvOccupation.Enabled = true;
        }
        else if (ddlInsuranceType.Text == "11")
        {
            rfvGarageType.Enabled = true;
            rfvCarYear.Enabled = true;
            rfvCarMake.Enabled = true;
            rfvModelBodyCCDoor.Enabled = true;
            rfvCTPL.Enabled = false;
            rfvModification.Enabled = false;
            rfvAccModAmount.Enabled = false;
            revAccModAmount.Enabled = false;
            rfvProvinceRegistration.Enabled = false;
            rfvAnyClaim.Enabled = false;
            rfvNCB.Enabled = false;
            rfvDriver1DOBDay.Enabled = false;
            rfvDriver1DOBMonth.Enabled = false;
            rfvDriver1DOBYear.Enabled = false;
            rfvDriver2DOBDay.Enabled = false;
            rfvDriver2DOBMonth.Enabled = false;
            rfvDriver2DOBYear.Enabled = false;
            rfvCoverageComDate.Enabled = true;
            rfvCurrentInsurer.Enabled = true;
            rfvFirstName.Enabled = true;
            revFirstName.Enabled = true;
            rfvLastName.Enabled = true;
            revLastName.Enabled = true;
            rfvEmailAddress.Enabled = true;
            revEmailAddress.Enabled = true;
            rfvGender.Enabled = true;
            rfvDOBDay.Enabled = true;
            rfvDOBMonth.Enabled = true;
            rfvDOBYear.Enabled = true;
            rfvOccupation.Enabled = true;
        }
        else if (ddlInsuranceType.Text == "21")
        {
            rfvGarageType.Enabled = true;
            rfvCarYear.Enabled = true;
            rfvCarMake.Enabled = true;
            rfvModelBodyCCDoor.Enabled = true;
            rfvCTPL.Enabled = false;
            rfvModification.Enabled = false;
            rfvAccModAmount.Enabled = false;
            revAccModAmount.Enabled = false;
            rfvProvinceRegistration.Enabled = false;
            rfvAnyClaim.Enabled = false;
            rfvNCB.Enabled = false;
            rfvDriver1DOBDay.Enabled = false;
            rfvDriver1DOBMonth.Enabled = false;
            rfvDriver1DOBYear.Enabled = false;
            rfvDriver2DOBDay.Enabled = false;
            rfvDriver2DOBMonth.Enabled = false;
            rfvDriver2DOBYear.Enabled = false;
            rfvCoverageComDate.Enabled = true;
            rfvCurrentInsurer.Enabled = true;
            rfvFirstName.Enabled = true;
            revFirstName.Enabled = true;
            rfvLastName.Enabled = true;
            revLastName.Enabled = true;
            rfvEmailAddress.Enabled = true;
            revEmailAddress.Enabled = true;
            rfvGender.Enabled = true;
            rfvDOBDay.Enabled = true;
            rfvDOBMonth.Enabled = true;
            rfvDOBYear.Enabled = true;
            rfvOccupation.Enabled = true;
        }
        else if (ddlInsuranceType.Text == "31")
        {
            rfvGarageType.Enabled = true;
            rfvCarYear.Enabled = true;
            rfvCarMake.Enabled = true;
            rfvModelBodyCCDoor.Enabled = true;
            rfvCTPL.Enabled = false;
            rfvModification.Enabled = false;
            rfvAccModAmount.Enabled = false;
            revAccModAmount.Enabled = false;
            rfvProvinceRegistration.Enabled = false;
            rfvAnyClaim.Enabled = false;
            rfvNCB.Enabled = false;
            rfvDriver1DOBDay.Enabled = false;
            rfvDriver1DOBMonth.Enabled = false;
            rfvDriver1DOBYear.Enabled = false;
            rfvDriver2DOBDay.Enabled = false;
            rfvDriver2DOBMonth.Enabled = false;
            rfvDriver2DOBYear.Enabled = false;
            rfvCoverageComDate.Enabled = true;
            rfvCurrentInsurer.Enabled = true;
            rfvFirstName.Enabled = true;
            revFirstName.Enabled = true;
            rfvLastName.Enabled = true;
            revLastName.Enabled = true;
            rfvEmailAddress.Enabled = true;
            revEmailAddress.Enabled = true;
            rfvGender.Enabled = true;
            rfvDOBDay.Enabled = true;
            rfvDOBMonth.Enabled = true;
            rfvDOBYear.Enabled = true;
            rfvOccupation.Enabled = true;
        }
        else if (ddlInsuranceType.Text == "30")
        {
            rfvGarageType.Enabled = false;
            rfvCarYear.Enabled = true;
            rfvCarMake.Enabled = true;
            rfvModelBodyCCDoor.Enabled = true;
            rfvCTPL.Enabled = true;
            rfvModification.Enabled = false;
            rfvAccModAmount.Enabled = false;
            revAccModAmount.Enabled = false;
            rfvProvinceRegistration.Enabled = false;
            rfvAnyClaim.Enabled = false;
            rfvNCB.Enabled = false;
            rfvDriver1DOBDay.Enabled = false;
            rfvDriver1DOBMonth.Enabled = false;
            rfvDriver1DOBYear.Enabled = false;
            rfvDriver2DOBDay.Enabled = false;
            rfvDriver2DOBMonth.Enabled = false;
            rfvDriver2DOBYear.Enabled = false;
            rfvCoverageComDate.Enabled = true;
            rfvCurrentInsurer.Enabled = true;
            rfvFirstName.Enabled = true;
            revFirstName.Enabled = true;
            rfvLastName.Enabled = true;
            revLastName.Enabled = true;
            rfvEmailAddress.Enabled = true;
            revEmailAddress.Enabled = true;
            rfvGender.Enabled = true;
            rfvDOBDay.Enabled = true;
            rfvDOBMonth.Enabled = true;
            rfvDOBYear.Enabled = true;
            rfvOccupation.Enabled = true;
        }
    }

    public void LoadInsuranceType()
    {
        ddlInsuranceType.Items.Clear();
        ddlInsuranceType.Items.Add(new ListItem(Resources.General.Select, "-1"));
        ddlInsuranceType.Items.Add(new ListItem(Resources.CarInsurance.Insurance_ClassOne, "10"));
        ddlInsuranceType.Items.Add(new ListItem(Resources.CarInsurance.Insurance_ClassOneLowCost, "11"));
        ddlInsuranceType.Items.Add(new ListItem(Resources.CarInsurance.Insurance_ClassTwo, "20"));
        ddlInsuranceType.Items.Add(new ListItem(Resources.CarInsurance.Insurance_ClassTwoPlus, "21"));
        ddlInsuranceType.Items.Add(new ListItem(Resources.CarInsurance.Insurance_ClassThreePlus, "31"));
        ddlInsuranceType.Items.Add(new ListItem(Resources.CarInsurance.Insurance_ClassThree, "30"));
    }

    public void LoadGarageType()
    {
        ddlGarageType.Items.Clear();
        ddlGarageType.Items.Add(new ListItem(Resources.General.Select, "-1"));
        ddlGarageType.Items.Add(new ListItem(Resources.CarInsurance.Garage_Authorized, "1"));
        ddlGarageType.Items.Add(new ListItem(Resources.CarInsurance.Garage_Dealer, "2"));
    }



    public void LoadDate(DropDownList ddl)
    {
        string val = "";
        ddl.Items.Clear();
        ddl.Items.Add(new ListItem(Resources.CarInsurance.Day, "-1"));
        for (int _date = 1; _date <= 31; _date++)
        {
            val = _date.ToString();
            if (_date < 10)
            {
                val = "0" + _date.ToString();
            }
            ddl.Items.Add(new ListItem(val, val));
        }
    }

    public void LoadMonth(DropDownList ddl)
    {
        string val = "";
        ddl.Items.Clear();
        ddl.Items.Add(new ListItem(Resources.CarInsurance.Month, "-1"));
        string monthname = Resources.General.Select;
        for (int _month = 1; _month <= 12; _month++)
        {
            val = _month.ToString();
            if (_month < 10)
            {
                val = "0" + _month.ToString();
            }
            else
            {
                val = _month.ToString();
            }
            if (_month == 1)
            {
                monthname = Resources.MonthResource.January;
            }
            else if (_month == 2)
            {
                monthname = Resources.MonthResource.February;
            }
            else if (_month == 3)
            {
                monthname = Resources.MonthResource.March;
            }
            else if (_month == 4)
            {
                monthname = Resources.MonthResource.April;
            }
            else if (_month == 5)
            {
                monthname = Resources.MonthResource.May;
            }
            else if (_month == 6)
            {
                monthname = Resources.MonthResource.June;
            }
            else if (_month == 7)
            {
                monthname = Resources.MonthResource.July;
            }
            else if (_month == 8)
            {
                monthname = Resources.MonthResource.August;
            }
            else if (_month == 9)
            {
                monthname = Resources.MonthResource.September;
            }
            else if (_month == 10)
            {
                monthname = Resources.MonthResource.October;
            }
            else if (_month == 11)
            {
                monthname = Resources.MonthResource.November;
            }
            else if (_month == 12)
            {
                monthname = Resources.MonthResource.December;
            }
            //ddl.Items.Clear();
            ddl.Items.Add(new ListItem(monthname, val));
        }
    }

    public void LoadYear(DropDownList ddl, int start, int end)
    {
        string ddlval = "";
        string ddltxt = "";
        ddl.Items.Clear();
        ddl.Items.Add(new ListItem(Resources.CarInsurance.Year, "-1"));
        for (int _year = start; _year >= end; _year--)
        {
            ddlval = _year.ToString();
            ddltxt = _year.ToString();
            if (lblLangOption.Text == "1")
            {
                ddltxt = (_year + 543).ToString();
            }
            ddl.Items.Add(new ListItem(ddltxt, ddlval));
        }
    }

    public void LoadOccupation()
    {
        DataTable dtOccupation = General.GetComboItem(Resources.CarInsurance.OccupationList, Resources.CarInsurance.OccupationSortBy, true);
        ddlOccupation.DataSource = dtOccupation;
        ddlOccupation.DataTextField = dtOccupation.Columns[0].ColumnName.ToString();
        ddlOccupation.DataValueField = dtOccupation.Columns[1].ColumnName.ToString();
        ddlOccupation.DataBind();
        ddlOccupation.Items.Insert(0, new ListItem(Resources.General.Select, "-1"));
    }

    public void LoadDOB()
    {
        int intStartYear = dateTimeNow.Year - 18;
        int intEndYear = dateTimeNow.Year - 90;

        LoadDate(ddlDOBDay);
        LoadMonth(ddlDOBMonth);
        LoadYear(ddlDOBYear, intStartYear, intEndYear);

        LoadDate(ddlDriver1DOBDay);
        LoadMonth(ddlDriver1DOBMonth);
        LoadYear(ddlDriver1DOBYear, intStartYear, intEndYear);

        LoadDate(ddlDriver2DOBDay);
        LoadMonth(ddlDriver2DOBMonth);
        LoadYear(ddlDriver2DOBYear, intStartYear, intEndYear);
    }

    public void LoadCommanceDate()
    {
        CultureInfo ci = new CultureInfo("th-TH");
        if (lblLangOption.Text == "2")
        {
            ci = new CultureInfo("en-US");
        }

        string defaultProMonth = "";

        DateTime dtNow = new DateTime();
        dtNow = dateTimeNow;
        for (int i = 2; i < 181; i++)
        {
            DateTime dtTemp = dtNow.AddDays(i);
            string strDate = dtTemp.Date.Day.ToString("00") + dtTemp.Date.Month.ToString("00") + dtTemp.Date.Year.ToString("0000");
            ddlCoverageComDate.Items.Add(new ListItem(dtTemp.ToString("dd/MMMM/yyyy", ci), strDate));

            // For Promotion only
            if (hidProComMonth.Value != "")
                if (defaultProMonth == "" && hidProComMonth.Value == dtTemp.Date.Month.ToString())
                    defaultProMonth = strDate;
        }
        ddlCoverageComDate.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));

        ddlCoverageComDate.SelectedIndex = ddlCoverageComDate.Items.IndexOf(ddlCoverageComDate.Items.FindByValue(
            defaultProMonth));
    }

    public void LoadCommanceDate(DateTime StartDate)
    {
        CultureInfo ci = new CultureInfo("th-TH");
        if (lblLangOption.Text == "2")
        {
            ci = new CultureInfo("en-US");
        }
        DateTime dtNow = new DateTime();
        dtNow = StartDate.AddDays(-30);
        ddlCoverageComDate.Items.Clear();
        for (int i = 2; i < 181; i++)
        {
            DateTime dtTemp = dtNow.AddDays(i);
            string strDate = dtTemp.Date.Day.ToString("00") + dtTemp.Date.Month.ToString("00") + dtTemp.Date.Year.ToString("0000");
            ddlCoverageComDate.Items.Add(new ListItem(dtTemp.ToString("dd/MMMM/yyyy", ci), strDate));
        }
        ddlCoverageComDate.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
    }

    private void LoadCarYear()
    {
        int _yearCount = 10;
        ddlCarYear.Items.Clear();

        if (ddlInsuranceType.Text != "-1")
        {
            if (Convert.ToInt32(ddlInsuranceType.Text) >= 20)
            {
                _yearCount = 25;
            }
            int _startYear = dateTimeNow.Year - _yearCount;
            int _endYear = dateTimeNow.Year;
            for (int i = _endYear; i >= _startYear; i--)
            {
                if (lblLangOption.Text.Trim() != "1")
                {
                    ddlCarYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
                }
                else
                {
                    ddlCarYear.Items.Add(new ListItem(i.ToString() + " - พ.ศ. " + (i + 543).ToString(), i.ToString()));
                }
            }
        }
        ddlCarYear.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
    }

    public void LoadCurrentInsurer()
    {
        DataTable dtPreInsurerComp = General.GetComboItem(Resources.DBTable.PreInsurer, Resources.DBTable.OrderByField, true);
        ddlCurrentInsurer.DataSource = dtPreInsurerComp;
        ddlCurrentInsurer.DataTextField = dtPreInsurerComp.Columns[0].ColumnName.ToString();
        ddlCurrentInsurer.DataValueField = dtPreInsurerComp.Columns[1].ColumnName.ToString();
        ddlCurrentInsurer.DataBind();
        ddlCurrentInsurer.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
    }

    public void LoadCallMeUser()
    {
        if (txtCallTypeId.Text != string.Empty && txtCallTypeId.Text == "102")
        {
            DataSet _dsSummary = new DataSet();
            DataTable _dtSummary = new DataTable();
            string _CallMeDate = dateTimeNow.Day.ToString("00");
            Int32 _CallTime = 0;
            Int16 _Language = Convert.ToInt16(lblLangOption.Text);
            string _SearchKey = "email";
            Int64 _CallMeId = Convert.ToInt16(txtCallMeId.Text);

            MyDatabase _db = new MyDatabase("GG_CRMDBConnectionString");
            string _spName = "[sprocCXCarInsuranceOfflineCallMeSelectUserList]";
            SortedList _sPara = new SortedList();

            _sPara.Add("@CallMeDate", _CallMeDate);
            _sPara.Add("@CallTime", _CallTime);
            _sPara.Add("@Language", _Language);
            _sPara.Add("@SearchKey", _SearchKey);
            _sPara.Add("@CallMeId", _CallMeId);

            _dsSummary = _db.GetDataSet(_spName, _sPara);
            if (_dsSummary != null && _dsSummary.Tables.Count > 0 && _dsSummary.Tables[0].Rows.Count > 0)
            {
                txtCallMeEmail.Text = _dsSummary.Tables[0].Rows[0]["Email"].ToString();
                txtCallMeFullName.Text = _dsSummary.Tables[0].Rows[0]["FullName"].ToString();
                txtCallMeMobileNo.Text = _dsSummary.Tables[0].Rows[0]["ContactNo"].ToString();

                txtEmailAddress.Text = _dsSummary.Tables[0].Rows[0]["Email"].ToString();
                txtFirstName.Text = _dsSummary.Tables[0].Rows[0]["FullName"].ToString();
                txtMobileNo.Text = _dsSummary.Tables[0].Rows[0]["ContactNo"].ToString();

                CarUserAccount _userAccount = GetCustomerAccount();

                if (_userAccount != null && _userAccount.CEID > 0)
                {
                    CarUserProfile _caruserprofile = new CarUserProfile();
                    CarUserProfileDB _caruserprofiledb = new CarUserProfileDB();
                    _caruserprofile = _caruserprofiledb.GetProfile(_userAccount.CEID);

                    if (_caruserprofile != null)
                    {
                        ddlDOBDay.Text = _caruserprofile.DOB.Day.ToString("00");
                        ddlDOBMonth.Text = _caruserprofile.DOB.Month.ToString("00");
                        ddlDOBYear.Text = _caruserprofile.DOB.Year.ToString("0000");
                        ddlGender.Text = _caruserprofile.Gender.ToString();
                        ddlOccupation.Text = _caruserprofile.Occupation.ToString();
                    }
                }
            }
        }
    }

    private CarUserAccount GetCustomerAccount()
    {
        CarUserAccount _caruseraccount = new CarUserAccount();
        CarUserAccountDB _caruseraccountdb = new CarUserAccountDB();
        _caruseraccount = _caruseraccountdb.GetUserAccount(txtEmailAddress.Text.Trim(), Convert.ToInt32(CE.Global.CEUserType.Customer));

       

        return _caruseraccount;

    }

    public DataSet GetCarDetails(Int64 CarId)
    {
        MyDatabase _db = new MyDatabase();
        string _spName = "sprocCXCRMCarDetailsSingleItemByCarId";

        SortedList _spara = new SortedList();
        _spara.Add("@CarId", CarId);

        DataSet _ds = _db.GetDataSet(_spName, _spara);

        return _ds;
    }

    private void ShowCarAndPolicyDetail(Int64 CarId, Int64 PolicyId, Int64 UserId, Int16 QuoteRenewStatus)
    {
        CarDetailTH _cardetail = new CarDetailTH();
        CarDetailTHDB _cardetaildb = new CarDetailTHDB();
        _cardetail = _cardetaildb.GetCar(CarId, UserId);

        CarPolicy _carpolicy = new CarPolicy();
        CarPolicyDB _carpolicydb = new CarPolicyDB();
        _carpolicy = _carpolicydb.GetCarPolicy(CarId, PolicyId, UserId);

        if (_carpolicy != null && _cardetail != null)
        {
            SetProperty(_carpolicy, _cardetail, QuoteRenewStatus);
        }

        MyDatabase _db = new MyDatabase();

        DataTable _dtTempUser = new DataTable("tblTempUser");
        _dtTempUser = _db.GetDataTable("select top 10 Brand_Name + ' ' + Family + ' ' + Body + ' ' + CAST(CC as varchar) + ' cc'  from tblTempBankUser Where UserID = " + UserId.ToString() + " And CarID = " + CarId.ToString());

        if (_dtTempUser != null && _dtTempUser.Rows.Count > 0)
        {
            lblOrgCarMakeModel.Text = "<br/>" + _dtTempUser.Rows[0][0].ToString();
        }

        _dtTempUser.Dispose();

        _db = null;

        _cardetail = null;
        _cardetaildb = null;

        _carpolicy = null;
        _carpolicydb = null;
    }

    private void SetProperty(CarPolicy _CarPolicy, CarDetailTH _CarDetail, Int16 QuoteRenewStatus)
    {
        CultureInfo ci = new CultureInfo("th-TH");
        if (lblLangOption.Text == "2")
        {
            ci = new CultureInfo("en-US");
        }

        _account = new CarUserAccount();
        _accountdb = new CarUserAccountDB();

        _account = _accountdb.GetAccount(_CarDetail.RefCEUserId);

        if (_account != null)
        {
            ShowCustomerDetail(_account);
        }
        else
        {
            lblMessage.Text = "[ERROR] Customer detail was not found!<br/><br/>Location:SetProperty(CarPolicy _CarPolicy, CarDetailTH _CarDetail, Int16 QuoteRenewStatus)";
        }

        ddlInsuranceType.Text = _CarPolicy.InsuranceType.ToString();
        ddlInsuranceType_SelectedIndexChanged(null, null);
        ddlGarageType.Text = _CarPolicy.GarageType.ToString();
        //LoadCarYear();
        ddlCarYear.Text = _CarDetail.ManufactYear.ToString();
        ddlCarYear_SelectedIndexChanged(null, null);
        ddlCurrentInsurer.SelectedIndex = ddlCurrentInsurer.Items.IndexOf(ddlCurrentInsurer.Items.FindByValue(_CarDetail.Info1));

        if (_account != null && _account.Status == true)
        {
            //[Yui] @ 08/08/2013
            //Car other
            if (!_CarDetail.BInfo1)
            {
                ddlCarMake.Text = _CarDetail.CarMakeName;
                ddlCarMake_SelectedIndexChanged(null, null);
                if (ddlCarMake.SelectedIndex >= 0)
                {
                    string _tempDesc = _CarDetail.CarModelName + " " + _CarDetail.Body + " " + _CarDetail.CC + "cc " + _CarDetail.Door.ToString() + " doors";

                    ddlModelBodyCCDoor.Text = _tempDesc;
                    //ddlModelBodyCCDoor_SelectedIndexChanged(null, null);
                }
            }
            else
            {
                ddlCarMake.Text = "-2";
                ddlCarMake_SelectedIndexChanged(null, null);
                ddlModelBodyCCDoor.Text = "-2";
                //ddlModelBodyCCDoor_SelectedIndexChanged(null, null);
                string[] carmakename = _CarDetail.MakeModelDesc.Split(' ');
                txtOtherCarMake.Text = (carmakename.Length > 1 ? carmakename[0] : _CarDetail.CarMakeName);
                txtOtherCarModel.Text = _CarDetail.CarModelName;
                ddlOtherCarBody.Text = _CarDetail.Body;
                txtCcCar.Text = _CarDetail.CC.ToString();
                ddlOtherCarDoor.Text = _CarDetail.Door.ToString();
            }

            //Yui@06062014
            //txtGroupNo.Text = _CarDetail.GroupNo.ToString();
            //lblCarVehicleType.Text = _CarDetail.Info2;
            //if (_CarDetail.Info3 == "110" || _CarDetail.Info3 == "210" || _CarDetail.Info3 == "320")
            //{
            //    ddlVehicleType.Text = "110";
            //}
            //else
            //{
            //    ddlVehicleType.Text = "120";
            //}
            //txtSumInsured.Text = _CarPolicy.SumInsured.ToString();
            //lblSumInsured.Text = Convert.ToInt32(txtSumInsured.Text).ToString("#,000");
            ddlModification.Text = Convert.ToInt16(_CarPolicy.IsAddAccMod).ToString();
            if (ddlModification.Text == "1")
            {
                txtAccModAmount.Text = _CarPolicy.AddAccModAmount.ToString();
                //txtNewSumInsured.Text = (_CarPolicy.SumInsured + _CarPolicy.AddAccModAmount).ToString();
                //lblSumInsured.Text = Convert.ToInt32(txtNewSumInsured.Text).ToString("#,000");
            }

            ddlDeduct.SelectedValue = Convert.ToInt32(_CarPolicy.Deductible) == 0 ? "0" : "-1";
            ddlProvinceRegistration.Text = _CarPolicy.ProvinceRegistration;
            lblTESCO200.Text = _CarPolicy.Info8.ToUpper();

            LoadCommanceDate(_CarPolicy.CoverageCommenceDate);

            ddlCoverageComDate.Text = _CarPolicy.CoverageCommenceDate.Day.ToString("00") + _CarPolicy.CoverageCommenceDate.Month.ToString("00") + _CarPolicy.CoverageCommenceDate.Year.ToString("0000");
            DateTime _dtCommDate = _CarPolicy.CoverageCommenceDate;
            _dtCommDate = _dtCommDate.AddDays(-1);
            _dtCommDate = _dtCommDate.AddYears(1);
            lblCoverageExpireDate.Text = _dtCommDate.ToString("dd/MMMM/yyyy", ci);
            ddlAnyClaim.Text = Convert.ToInt16(_CarPolicy.IsClaimLastYear).ToString();
            ddlNamedDrivers.Text = _CarPolicy.NoOfDriver.ToString();
            ddlNamedDrivers_SelectedIndexChanged(null, null);
            ddlCTPL.Text = Convert.ToInt16(_CarPolicy.IsCTPL).ToString();
            ddlNCB.Text = _CarPolicy.NCDPercent.ToString();
            txtFirstName.Text = _CarDetail.Info8;
            txtLastName.Text = _CarDetail.Info7;
            txtMobileNo.Text = _CarDetail.Info6;
            txtEmailAddress.Text = _CarDetail.Info5;

            if (_CarPolicy.Info6.Length > 0 && _CarPolicy.Info7.Length > 0)
            {
                divLastYearRefNo.Visible = true;
                lblLastYearCarID.Text = _CarPolicy.Info6;
                lblLastYearRefNo.Text = _CarPolicy.Info7;
            }

            if (_CarPolicy.NoOfDriver > 0)
            {
                DataTable _dtDriver = new DataTable();
                CarDriverDB _carDriverdb = new CarDriverDB();
                _dtDriver = _carDriverdb.GetDriverList(_CarDetail.CarId, _CarDetail.RefCEUserId);
                if (_dtDriver != null && _dtDriver.Rows.Count > 0)
                {
                    txtDriverId1.Text = _dtDriver.Rows[0]["CarDriverId"].ToString();
                    DateTime _DriverDOB1 = new DateTime();
                    DateTime.TryParse(_dtDriver.Rows[0]["DOB"].ToString(), out _DriverDOB1);
                    ddlDriver1DOBDay.Text = _DriverDOB1.Day.ToString("00");
                    ddlDriver1DOBMonth.Text = _DriverDOB1.Month.ToString("00");
                    ddlDriver1DOBYear.Text = _DriverDOB1.Year.ToString("0000");
                    if (_dtDriver != null && _dtDriver.Rows.Count > 1)
                    {
                        txtDriverId2.Text = _dtDriver.Rows[1]["CarDriverId"].ToString();
                        DateTime _DriverDOB2 = new DateTime();
                        DateTime.TryParse(_dtDriver.Rows[1]["DOB"].ToString(), out _DriverDOB2);
                        ddlDriver2DOBDay.Text = _DriverDOB2.Day.ToString("00");
                        ddlDriver2DOBMonth.Text = _DriverDOB2.Month.ToString("00");
                        ddlDriver2DOBYear.Text = _DriverDOB2.Year.ToString("0000");
                    }
                }

            }
            ValidateControlEnable();
           
        }
        else
        {
            ddlDeduct.Text = "-1";
            ddlCoverageComDate.Text = dateTimeNow.AddDays(45).ToString("ddMMyyyy");
            ddlProvinceRegistration.Text = "BKK";
            ddlAnyClaim.Text = "0";
            ddlAnyClaim_SelectedIndexChanged(null, null);
            ddlNCB.Text = "20";
            ddlModification.Text = "0";
            ddlModification_SelectedIndexChanged(null, null);
        }
    }

    private bool ShowScreen(Int64 AgentLeadID, Int16 CallType, Int64 CarID, Int64 CustomerID)
    {
        //DIFFERENT - NON-GG PACKAGES
        //Car ID and Customer ID got from Query String

        bool _retValue = false;
        try
        {
            string _spName = "sprocCXCRMGetCarDetailSelectSingleItemByAgentLeadID";
            MyDatabase _db = new MyDatabase();
            DataTable _dtCarDetail = new DataTable("tblCar");
            SortedList _paraList = new SortedList();
            _paraList.Add("@AgentLeadID", AgentLeadID);
            _paraList.Add("@CallType", txtCallTypeId.Text);
            _paraList.Add("@LangOption", lblLangOption.Text);
            _dtCarDetail = _db.GetDataTableBySP(_spName, _paraList);
            if (_dtCarDetail != null && _dtCarDetail.Rows.Count > 0)
            {
                txtAgentLeadId.Text = _dtCarDetail.Rows[0][0].ToString();
                txtCallMeId.Text = _dtCarDetail.Rows[0][5].ToString();
                txtCarId.Text = CarID.ToString();
                txtCustomerId.Text = CustomerID.ToString();
                lblRedirectCustomerId.Text = txtCustomerId.Text;
                _retValue = true;
            }
            else
            {
                _retValue = false;
            }

            if (_dtCarDetail.Columns.Contains("PromotionId"))
            {
                if (_dtCarDetail.Rows[0]["PromotionId"].ToString() != "")
                {
                    hidPromotionId.Value = _dtCarDetail.Rows[0]["PromotionId"].ToString();
                    //28March2014
                    GetPromotion();
                }
            }
        }
        catch (Exception Ex)
        {
            _retValue = false;
            lblCallSessionName.Text += "<br/><b style='color:red;'>" + Resources.General.ERROR + "</b>: at ShowScreen(Int64 AgentLeadID, Int16 CallType)<br/>" + Ex.Message + "<br/><br/>" + Ex.StackTrace;
        }

        return _retValue;
    }

    private bool ShowScreen()
    {
        bool _retValue = false;
        try
        {
            string _spName = "sprocCXCRMGetCarDetailSelectSingleItem";
            MyDatabase _db = new MyDatabase();
            DataTable _dtCarDetail = new DataTable("tblCar");
            SortedList _paraList = new SortedList();
            _paraList.Add("@AgentID", Session[General.UserId].ToString());
            _paraList.Add("@CallType", txtCallTypeId.Text);
            _paraList.Add("@LangOption", lblLangOption.Text);

            _dtCarDetail = _db.GetDataTableBySP(_spName, _paraList);
            if (_dtCarDetail != null && _dtCarDetail.Rows.Count > 0)
            {
                txtAgentLeadId.Text = _dtCarDetail.Rows[0][0].ToString();
                txtCallMeId.Text = _dtCarDetail.Rows[0][5].ToString();
                if (txtCallTypeId.Text != string.Empty && txtCallTypeId.Text == "102")
                {
                    if (txtNewQuote.Text == string.Empty || txtNewQuote.Text == "0")
                    {
                        txtCustomerId.Text = _dtCarDetail.Rows[0][1].ToString();
                        txtCarId.Text = _dtCarDetail.Rows[0][2].ToString();
                        lblRedirectCustomerId.Text = txtCustomerId.Text;
                    }
                }
                _retValue = true;
            }
            else
            {
                _retValue = false;
            }
        }
        catch (Exception Ex)
        {
            _retValue = false;
            lblCallSessionName.Text += "<br/><b style='color:red;'>" + Resources.General.ERROR + "</b>: at ShowScreen()<br/>" + Ex.Message + "<br/><br/>" + Ex.StackTrace;
        }
        return _retValue;
    }

    protected void ShowCallStatus(Int64 AgentLeadId, Int32 CallTypeID)
    {
        #region Call Status
        ddlCICallStatus.Enabled = true;
        divCallStatus.Visible = true;

        CallStatus CI_callstatus = new CallStatus();
        CallStatusDB CI_callstatusdb = new CallStatusDB();
        CI_callstatus = CI_callstatusdb.GetCallStatus(AgentLeadId, CallTypeID);

        if (CI_callstatus != null)
        {

            txtCXCRMId.Text = CI_callstatus.CXCRMId.ToString();

            txtCallBackDateTime.Text = "0";

            rdoCallFinish.Checked = false;
            rdoCallBack.Checked = false;
            rdoCallNotBuy.Checked = false;
            lblCallSessionName.Text = "<table class='sTable'>";

            if (CI_callstatus.CallFinishType == 1)
            {
                rdoCallFinish.Checked = true;
                lblCallSessionName.Text += "<tr><td><b style='color:red;'>" + Resources.General.CLOSEDCALL + "</b></td>";
            }
            else if (CI_callstatus.CallFinishType == 2)
            {
                rdoCallBack.Checked = true;
                ddlCBAgentList.Text = CI_callstatus.CallBackAgentID.ToString();
                txtCallBackDateTime.Text = CI_callstatus.CallBackDateTime.ToString("dd/MMM/yyyy hh:mm tt");
                lblCallSessionName.Text += "<tr><td><b style='color:red;'>" + Resources.General.Callback.ToUpper() + "</b></td><td>" + txtCallBackDateTime.Text + "</td>";
                DateTime _dtTargetDateTime = dateTimeNow;
                if (DateTime.TryParse(txtCallBackDateTime.Text, out _dtTargetDateTime))
                {
                    
                    txtTargetDate.Text = _dtTargetDateTime.ToString("dd-MMM-yyyy");
                    ddlTHour.SelectedIndex = ddlTHour.Items.IndexOf(ddlTHour.Items.FindByValue(_dtTargetDateTime.ToString("HH")));
                    ddlTMin.Text = _dtTargetDateTime.Minute.ToString("00");
                }
                else
                {
                    txtCallBackDateTime.Text = "0";
                }
            }
            else if (CI_callstatus.CallFinishType == 3)
            {
                //rdoFollowUp.Checked = true;
                lblCallSessionName.Text += "<tr><td><b style='color:blue;'>" + Resources.General.FollowUp.ToUpper() + "</b></td>";
            }

            lblCallSessionName.Text += "</tr></table>";

            rdoCallFinish_CheckedChanged(null, null);
            if (ddlCIMainCallStatus.Items.Count > 0)
            {
                ddlCIMainCallStatus.Text = CI_callstatus.MainCallStatusTypeID.ToString();
                ddlCIMainCallStatus_SelectedIndexChanged(null, null);

                if (ddlCICallStatus.Items.Count > 0)
                {
                    ddlCICallStatus.Text = CI_callstatus.CallStatusTypeID.ToString();
                }
            }

            txtCallStatus.Text = Server.HtmlDecode(CI_callstatus.Remark);
            lblLastCallStatusMessage.Text = Resources.General.FOUND + " [" + Resources.General.LastDateTime + ": " + CI_callstatus.ModifiedDate.ToString("dd/MMM/yyyy hh:mm tt") + "]";
        }
        else
        {
            lblLastCallStatusMessage.Text = Resources.General.NEW;
            lblCallSessionName.Text = Resources.General.NEWCALLPENDING;
        }

        CI_callstatus = null;
        CI_callstatusdb = null;
        #endregion
    }

    protected void ddlCICallStatus_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlCICallStatus.Text == "10")
        {
            //ddlCIMainCallStatus.Text == "7" && 
            //lblCallBackDateTime.Text = Resources.CarInsurance.NewCommencementDate;
            //txtTargetDate.Text = dateTimeNow.ToString("dd-MMM-yyyy");
            //cexTargetDate.StartDate = dateTimeNow;
            //cexTargetDate.EndDate = dateTimeNow.AddDays(180);
            //trCallBack1.Visible = true;
            //spanTimeDrowdown.Visible = false;

            //27Feb2014
            //txtTargetDate.Text = dateTimeNow.AddDays(61).ToString("dd-MMM-yyyy");
            //cexTargetDate.StartDate = dateTimeNow.AddDays(61);
            //11Mar2014
            txtTargetDate.Text = dateTimeNow.AddDays(1).ToString("dd-MMM-yyyy");
            cexTargetDate.StartDate = dateTimeNow.AddDays(1);
            cexTargetDate.EndDate = dateTimeNow.AddDays(180);
            // lee @24/03/2015 move to page load
            //ddlCBAgentList.SelectedIndex = ddlCBAgentList.Items.IndexOf(ddlCBAgentList.Items.FindByValue(Session[General.UserId].ToString()));
            trCallBack1.Visible = true;
        }
        else
        {
            if (rdoCallBack.Checked)
            {
                txtTargetDate.Text = dateTimeNow.ToString("dd-MMM-yyyy");
                cexTargetDate.StartDate = dateTimeNow;
                cexTargetDate.EndDate = GetCallBackDateLimit(15);
                // lee @24/03/2015 move to page load
                //ddlCBAgentList.SelectedIndex = ddlCBAgentList.Items.IndexOf(ddlCBAgentList.Items.FindByValue(Session[General.UserId].ToString()));
            }
        }
    }

    private DateTime GetCallBackDateLimit(int limitDate)
    {
        DateTime dateTimeCallback = new DateTime();
        try
        {
            MyDatabase _db = new MyDatabase();
            object rtnDate = _db.ExecuteScalarSqlStatement("SELECT dbo.fn_countDateNoHolliday(dbo.fn_getUTCDateTime()," + limitDate.ToString() + ",1) CallBackDate");
            if (rtnDate != null)
            {
                dateTimeCallback = Convert.ToDateTime(rtnDate);
            }
            else
            {
                dateTimeCallback = dateTimeNow.AddDays(21);
            }
        }
        catch (Exception)
        {
        }
        return dateTimeCallback;
    }

    #region Promotion

    private void GetPromotion()
    {
        PromotionGGDB objPro = new PromotionGGDB();
        DataTable _dt = objPro.GetPromotion(Int64.Parse(hidPromotionId.Value));
        if (_dt.Rows.Count > 0)
        {
            ltrPromotion.Text = "<table border=\"0\" style=\"width:100%\">";
            foreach (DataRow drPro in _dt.Rows)
            {
                ltrPromotion.Text += "<tr>";
                ltrPromotion.Text += "<td>Promotion:</td><td colspan=\"5\"><b style='color:red;'>" + drPro["PromotionName"].ToString() + "</b></td>";
                System.Globalization.CultureInfo cul = new System.Globalization.CultureInfo("th-TH");
                ltrPromotion.Text += "</tr>";
                ltrPromotion.Text += "<tr>";
                ltrPromotion.Text += "<td>" + Resources.CarInsurance.CoverCommencementDate + ":</td><td><b style='color:blue;'>" + cul.DateTimeFormat.GetMonthName(int.Parse(drPro["CommencementMonth"].ToString())) + "</b></td>";
                hidProComMonth.Value = drPro["CommencementMonth"].ToString();
                ltrPromotion.Text += "<td>" + Resources.CarInsurance.CallTime + ":</td><td><b style='color:green;'>" + GetCallAt(int.Parse(drPro["CallAt"].ToString())) + "</b></td>";
                ltrPromotion.Text += "<td>" + Resources.General.Requestedon + ":</td><td><b style='color:red;'>" + Convert.ToDateTime(drPro["CreatedDate"].ToString()).ToString("dd/MMM/yyyy hh:mm:ss tt") + "</b></td>";
                ltrPromotion.Text += "</tr>";
            }
            ltrPromotion.Text += "</table>";
        }
    }

    private string GetCallAt(int callAt)
    {
        switch (callAt)
        {
            case 1:
                return "ตอนเช้า";
            case 2:
                return "ตอนบ่าย";
            case 3:
                return "ตอนเย็น";
            case 4:
                return "ทุกเวลา";
            default: 
                return "";
        }
    }

    #endregion

    private void GetCarMakeList(string Year, DropDownList ddlList)
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable("tblMake");
        SortedList _spList = new SortedList();
        _spList.Add("@Year", Year);
        _dt = _db.GetDataTableBySP("sprocGetCarMakeTHListByYear", _spList);
        ddlList.Items.Clear();
        ddlList.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        if (_dt != null && _dt.Rows.Count > 0)
        {
            for (int i = 0; i < _dt.Rows.Count; i++)
            {
                ddlList.Items.Add(new ListItem(_dt.Rows[i][1].ToString(), _dt.Rows[i][0].ToString()));
            }
        }

       
        ddlList.Items.Insert(ddlList.Items.Count, new ListItem(Resources.CarInsurance.Other, "-2"));

        _dt = null;
        _db = null;
    }

    private void GetCarModelDescList(string CarMake, string Year, DropDownList ddlList)
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable("tblModelDesc");
        SortedList _spList = new SortedList();
        _spList.Add("@CarMake", CarMake);
        _spList.Add("@Year", Year);

        _dt = _db.GetDataTableBySP("sprocKawnaGetCarModelDescListByCarMakeCode", _spList);
        ddlList.Items.Clear();
        if (_dt != null && _dt.Rows.Count > 0)
        {
            ddlList.DataSource = _dt;
            ddlList.DataTextField = "CarModelDisplay";
            ddlList.DataValueField = "CarModelDesc";
            ddlList.DataBind();
            ddlList.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));

            divOtherCar.Style.Add("display", "none");
            rfvOtherCarMake.Enabled = false;
            rfvOtherCarModel.Enabled = false;
            rfvOtherCarBody.Enabled = false;
            rfvCcCar.Enabled = false;
            revCcCar.Enabled = false;
            txtOtherCarMake.Text = "";
            txtOtherCarModel.Text = "";
            txtCcCar.Text = "";
            //rfvSumInsured.Enabled = true;
        }
        else
        {
            ddlList.Items.Insert(ddlList.Items.Count, new ListItem(Resources.CarInsurance.Other, "-2"));
            divOtherCar.Style.Add("display", "");
            rfvOtherCarMake.Enabled = true;
            rfvOtherCarModel.Enabled = true;
            rfvOtherCarBody.Enabled = true;
            rfvCcCar.Enabled = true;
            revCcCar.Enabled = true;
            //rfvSumInsured.Enabled = false;
        }
        
        _dt = null;
        _db = null;
    }

    private void GetCarModelSumInsuredAmountAndVehicleType(string CarMake, string CarModel, string Body, string CC, string Door, string Year, TextBox txtTextBox, Label lblLabel, Label lblLabelTwo)
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable("tblModelBody");
        SortedList _spList = new SortedList();
        _spList.Add("@CarMake", CarMake);
        _spList.Add("@CarModel", CarModel);
        _spList.Add("@Body", Body);
        _spList.Add("@CC", CC);
        _spList.Add("@Door", Door);
        _spList.Add("@Year", Year);
        _dt = _db.GetDataTableBySP("sprocGetCarModelSumInsuredAndVehicleTypeTHListByYear", _spList);
        if (_dt != null && _dt.Rows.Count > 0)
        {
            txtTextBox.Text = _dt.Rows[0][0].ToString();
            lblLabelTwo.Text = _dt.Rows[0][1].ToString();
            lblLabel.Text = Convert.ToInt32(txtTextBox.Text).ToString("#,000");
           
        }
        else
        {
            txtTextBox.Text = "0";
            lblLabel.Text = "0";
        }
        txtTextBox.ReadOnly = true;
        _dt = null;
        _db = null;
    }

    private void GetCarModelGroupNo(string CarMake, string CarModel, string Body, string CC, string Door, TextBox txtTextBox)
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable("tblModelBody");
        SortedList _spList = new SortedList();
        _spList.Add("@CarMake", CarMake);
        _spList.Add("@CarModel", CarModel);
        _spList.Add("@Body", Body);
        _spList.Add("@CC", CC);
        _spList.Add("@Door", Door);
        _dt = _db.GetDataTableBySP("sprocGetCarModelGroupTH", _spList);

        if (_dt != null && _dt.Rows.Count > 0)
        {
            txtTextBox.Text = _dt.Rows[0][0].ToString();
        }
        else
        {
            txtTextBox.Text = "0";
        }
        txtTextBox.ReadOnly = true;
        _dt = null;
        _db = null;
    }

    private void CalculatePremiumCRM()
    {
        MyDatabase _db = new MyDatabase();
        SortedList _sPara = new SortedList();
        string _spName = "[sprocProviderCarInsuranceClearExcel]";
        _sPara = new SortedList();
        _sPara.Add("@CarId", txtCarId.Text);
        _db.ExecuteNonSqlSP(_spName, _sPara);

       
    }

    private Int32 CalculatePremium()
    {
        MyDatabase _db = new MyDatabase();

        SortedList _sPara = new SortedList();
      
        _sPara.Add("@CarId", txtCarId.Text);
        Int64 _carId = Convert.ToInt64(txtCarId.Text);
        Int64 _userId = 0;
        BKIDetailDB bki = new BKIDetailDB();

        if (txtCustomerId.Text != string.Empty)
        {
            _userId = Convert.ToInt64(txtCustomerId.Text);
        }
        _sPara.Add("@RefUserId", _userId);

        Int32 _result = 0;


        _db.ExecuteNonSqlSP("[sprocProviderCarInsuranceClear]", _sPara);


        if (Convert.ToInt32(Session[CE.Global.General.UserTypeId]) ==
                Convert.ToInt32(CE.Global.CEUserType.Provider) && Session[CE.Global.General.ProviderCompanyId] != null)
        {
            if (Session[CE.Global.General.ProviderCompanyId].ToString() == CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.AZCPProviderCompanyID"))
                _result = _db.ExecuteNonSqlSP("[sprocAZCPCarInsuranceCalculation]", _sPara);
            else if (Session[CE.Global.General.ProviderCompanyId].ToString() == CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.AXAProviderCompanyID"))
                _result = _db.ExecuteNonSqlSP("[sprocAXACarInsuranceCalculation]", _sPara);
            else if (Session[CE.Global.General.ProviderCompanyId].ToString() == CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.MSIGProviderCompanyID"))
                _result = _db.ExecuteNonSqlSP("[sprocMSIGCarInsuranceCalculation]", _sPara);
            else if (Session[CE.Global.General.ProviderCompanyId].ToString() == CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.LMGProviderCompanyID"))
                _result = _db.ExecuteNonSqlSP("[sprocLMGCarInsuranceCalculation]", _sPara);
            else if (Session[CE.Global.General.ProviderCompanyId].ToString() == CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ChartisProviderCompanyID"))
                _result = _db.ExecuteNonSqlSP("[sprocChartisCarInsuranceCalculation]", _sPara);
            //else if (Session[CE.Global.General.ProviderCompanyId].ToString() == CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.BKIProviderCompanyID"))
            //{}
        }
        else
        {
            ////====Test Web Service
            try
            {
                bki.BKICalculation(_carId, _userId);
            }
            catch
            {
            }

            _result = _db.ExecuteNonSqlSP("[sprocProviderCarInsuranceCalculation]", _sPara);
        }
        return _result;
    }

    private void ResultsQuotesDataBind()
    {
        GetTempResultTableTwo();
        DataView dv = new DataView();
        if (txtCustomerId.Text != string.Empty)
        {
            dv = new DataView((DataTable)Cache["CarResult" + txtCustomerId.Text + txtCarId.Text]);
        }
        else
        {
            dv = new DataView((DataTable)Cache["CarResult" + txtCarId.Text]);
        }

        gvCarResult.DataSource = dv;
        gvCarResult.DataBind();
        gvCarResult.Visible = true;
        divResult.Visible = true;
    }

    private void GetTempResultTableTwo()
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dtResult = new DataTable();
        string _spName = "[sprocCarInsuranceResultCallMeSelectItemList]";
        SortedList _sPara = new SortedList();
        //test
        _sPara.Add("@CarId", txtCarId.Text);

        if (txtCustomerId.Text != string.Empty)
        {
            _sPara.Add("@RefUserId", txtCustomerId.Text);
        }
        else
        {
            _sPara.Add("@RefUserId", 0);
        }
        if (Convert.ToInt64(txtAgentId.Text) > 0)
        {
            _sPara.Add("@AgentId", Convert.ToInt64(txtAgentId.Text));
        }
        else
        {
            _sPara.Add("@AgentId", 0);
        }
        _dtResult = _db.GetDataTableBySP(_spName, _sPara);

        if (txtCustomerId.Text != string.Empty)
        {
            Cache["CarResult" + txtCustomerId.Text + txtCarId.Text] = _dtResult;
        }
        else
        {
            Cache["CarResult" + txtCarId.Text] = _dtResult;
        }

    }


    protected void gvCarResult_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            foreach (TableCell cell in e.Row.Cells)
            {
                if (cell.HasControls())
                {
                    LinkButton button = cell.Controls[0] as LinkButton;
                    if (button != null)
                    {
                        Image imageSort = new Image();
                        imageSort.ImageUrl = "~/OLD/images/icons/clear.gif";
                        HtmlGenericControl gv = new HtmlGenericControl("div");
                        Label lnkName = new Label();
                        lnkName.Text = button.Text;

                        if (ViewState["SortExpression"] != null && ViewState["SortExpression"].ToString() == button.CommandArgument.ToString())
                        {
                            if (ViewState["SortOrder"] != null && ViewState["SortOrder"].ToString() == SortDirection.Descending.ToString())
                            {
                                imageSort.ImageUrl = "~/OLD/images/icons/Sort_Down.gif";
                            }
                            else
                            {
                                imageSort.ImageUrl = "~/OLD/images/icons/Sort_Up.gif";
                            }
                        }
                        gv.Controls.Add(lnkName);
                        gv.Controls.Add(imageSort);
                        button.Controls.Add(gv);
                    }
                }
            }

            //Creat Custome Header
            GridView HeaderGrid = (GridView)sender;
            GridViewRow HeaderGridRow =
            new GridViewRow(0, 0, DataControlRowType.Header,
            DataControlRowState.Insert);

            TableCell HeaderCell = new TableCell();
            HeaderCell.Text = "";
            HeaderCell.HorizontalAlign = HorizontalAlign.Center;
            HeaderCell.ColumnSpan = 3;
            HeaderGridRow.Cells.Add(HeaderCell);

            HeaderCell = new TableCell();
            HeaderCell.Text = "<img src='../../images/arrows/arrow-down.png\'  />" + Resources.CarInsuranceResultPage.OwnDamage + "<img src=\"../../images/arrows/arrow-down.png\" align=\"absmiddle\" alt=\"\" />";
            HeaderCell.Font.Bold = true;
            HeaderCell.ControlStyle.CssClass = "green_top";
            HeaderCell.HorizontalAlign = HorizontalAlign.Center;
            HeaderCell.ColumnSpan = 2;
            HeaderGridRow.Cells.Add(HeaderCell);

            HeaderCell = new TableCell();
            HeaderCell.Text = "<img src=\"../../images/arrows/arrow-down.png\" align=\"absmiddle\" alt=\"\" /> " + Resources.CarInsuranceResultPage.ThirdPartyLiability + "<img src=\"../../images/arrows/arrow-down.png\" align=\"absmiddle\" alt=\"\" /><br/>" + Resources.CarInsuranceResultPage.PerAccident;
            HeaderCell.Font.Bold = true;
            HeaderCell.ControlStyle.CssClass = "blue_top";
            HeaderCell.HorizontalAlign = HorizontalAlign.Center;
            HeaderCell.ColumnSpan = 3;
            HeaderGridRow.Cells.Add(HeaderCell);

            HeaderCell = new TableCell();
            HeaderCell.Text = "<img src=\"../../images/arrows/arrow-down.png\" align=\"absmiddle\" alt=\"\" />" + Resources.CarInsuranceResultPage.AdditionalCovers + "<img src=\"../../images/arrows/arrow-down.png\" align=\"absmiddle\" alt=\"\" />";
            HeaderCell.Font.Bold = true;
            HeaderCell.ControlStyle.CssClass = "gold_top";
            HeaderCell.HorizontalAlign = HorizontalAlign.Center;
            HeaderCell.ColumnSpan = 3;
            HeaderGridRow.Cells.Add(HeaderCell);

            HeaderCell = new TableCell();
            HeaderCell.Text = "";
            HeaderCell.HorizontalAlign = HorizontalAlign.Center;
            //HeaderCell.ColumnSpan = 3;
            HeaderGridRow.Cells.Add(HeaderCell);

            gvCarResult.Controls[0].Controls.AddAt
            (0, HeaderGridRow);
        }
    }

    protected void gvCarResult_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //HIDE
        //For Thailand
        if (e.Row.RowType == DataControlRowType.DataRow)
        {


            string _callCarProviderId = "";


            string _companyId = DataBinder.Eval(e.Row.DataItem, "ProviderCompanyId").ToString();
           

            _callCarProviderId = _companyId;

            if (e.Row.DataItem != null)
            {
                _currentRow += 1;
                
            }

            HtmlGenericControl divFrame = new HtmlGenericControl("div");
            divFrame.Attributes.Add("id", "framework_moreinfo");

            HtmlGenericControl divContainer = new HtmlGenericControl("div");
            divContainer.Attributes.Add("id", "container_moreinfo");

            HtmlGenericControl divContent = new HtmlGenericControl("div");
            divContent.Attributes.Add("id", "content_moreinfo");

            Label lblPolicyInfoId = new Label();
            lblPolicyInfoId = (Label)e.Row.FindControl("lblPolicyInfoId");
            object _objPolicyinfoId = 4;//DataBinder.Eval(e.Row.DataItem, "NInfo3");

            Label lblPromoId = new Label();
            lblPromoId = (Label)e.Row.FindControl("lblPromoId");
            object _objPromoId = 11;//DataBinder.Eval(e.Row.DataItem, "NInfo2");

            Label lblPolicyId = new Label();
            lblPolicyId = (Label)e.Row.FindControl("lblPolicyId");
            object _objPolicyId = 5;//DataBinder.Eval(e.Row.DataItem, "NInfo1");

            

            //CXCoverTypeId

            if (_objPolicyinfoId != null && _objPromoId != null && _objPolicyId != null)
            {

            }

            Label lblResultPromotionPrice = new Label();
            lblResultPromotionPrice = (Label)e.Row.FindControl("lblResultPromotionPrice");

            Label lblResultAnnualPremium = new Label();
            lblResultAnnualPremium = (Label)e.Row.FindControl("lblResultAnnualPremium");

            string _PromotionPrice = DataBinder.Eval(e.Row.DataItem, "PromotionPrice").ToString();
            decimal _dPromotionPrice = 0;
            if (!decimal.TryParse(_PromotionPrice, out _dPromotionPrice))
            {
                _dPromotionPrice = 0;
            }
            lblResultPromotionPrice.Text = _dPromotionPrice.ToString("#0,000.00");

            string _TotalAnnualPremium = DataBinder.Eval(e.Row.DataItem, "AnnualPremium").ToString();
            decimal _dTotalAnnualPremium = 0;
            if (!decimal.TryParse(_TotalAnnualPremium, out _dTotalAnnualPremium))
            {
                _dTotalAnnualPremium = 0;
            }
            lblResultAnnualPremium.Text = _dTotalAnnualPremium.ToString("#0,000.00");


            //Company Logo and Cover Type
            Label lblCoverTypeDesc = (Label)e.Row.FindControl("lblPackageName");
            Image imgCompanyLogo = (Image)e.Row.FindControl("imgCompanyLogo");

            string _logoUrl = DataBinder.Eval(e.Row.DataItem, "CompanyLogoServerUrl").ToString();
            string _coverTypeDesc = DataBinder.Eval(e.Row.DataItem, "PackageName").ToString().Trim();

            imgCompanyLogo.ImageUrl = "~" + _logoUrl;
            imgCompanyLogo.ToolTip = _coverTypeDesc;
            lblCoverTypeDesc.Text = _coverTypeDesc;
           

            ////CTPL
            Label lblCTPL = (Label)e.Row.FindControl("lblCTPL");
            Label lblCTPLSymbol = (Label)e.Row.FindControl("lblCTPLSymbol");
            Image imgCTPL = (Image)e.Row.FindControl("imgCTPL");
            string _totalCMI = DataBinder.Eval(e.Row.DataItem, "TotalCMI").ToString().Trim();

            if (_totalCMI != null && _totalCMI != string.Empty && Convert.ToSingle(_totalCMI) > 0.0f)
            {
                imgCTPL.Visible = false;
                lblCTPL.Text = _totalCMI;
                lblCTPL.Visible = true;
                lblCTPLSymbol.Visible = true;
            }
            else
            {
                imgCTPL.Visible = true;
                lblCTPL.Text = "0";
                lblCTPL.Visible = false;
                lblCTPLSymbol.Visible = false;
            }
            ////END CTPL

            //// DEC
            Label lblDEC = (Label)e.Row.FindControl("lblDEC");
            Label lblDECSymbol = (Label)e.Row.FindControl("lblDECSymbol");
            Label lblDECZero = (Label)e.Row.FindControl("lblDECZero");
            string _DEC = DataBinder.Eval(e.Row.DataItem, "DEC").ToString().Trim();

            if (_DEC != null && _DEC != string.Empty && Convert.ToSingle(_DEC) > 0.0f)
            {
                lblDECZero.Visible = false;
                lblDEC.Text = _DEC;
                lblDEC.Visible = true;
                lblDECSymbol.Visible = true;
            }
            else
            {
                lblDECZero.Visible = true;
                lblDEC.Text = "0";
                lblDEC.Visible = false;
                lblDECSymbol.Visible = false;
            }
            //// END DEC

            ///SUM INSURED OR OWN DAMAGE FIRE OR THIEF
            Label lblSumInsured = (Label)e.Row.FindControl("lblSumInsured");
            Label lblSumInsuredSymbol = (Label)e.Row.FindControl("lblSumInsuredSymbol");
            Image imgSumInsured = (Image)e.Row.FindControl("imgSumInsured");
            string _sumInsured = DataBinder.Eval(e.Row.DataItem, "SumInsured").ToString().Trim();

            if (_sumInsured != null && _sumInsured != string.Empty && Convert.ToSingle(_sumInsured) > 0.0f)
            {
                imgSumInsured.Visible = false;
                lblSumInsured.Text = Convert.ToInt32(_sumInsured).ToString("#,000"); //_sumInsured;
                lblSumInsured.Visible = true;
                lblSumInsuredSymbol.Visible = true;
            }
            else
            {
                imgSumInsured.Visible = true;
                lblSumInsured.Text = "0";
                lblSumInsured.Visible = false;
                lblSumInsuredSymbol.Visible = false;
            }
            ///END SUM INSURED OR OWN DAMAGE FIRE OR THIEF

            //GARAGE

            //HyperLink hplnkWorkshop = new HyperLink();
            HyperLink hplnkWorkshop = (HyperLink)e.Row.FindControl("hplWorkshopLink");
            
            hplnkWorkshop.Target = "_blank";
            hplnkWorkshop.Font.Bold = true;
            if (_companyId == "11")
            {
                // "Allianz C.P";
                if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.AllianceWorkshopTH");
                }
                else
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.AllianceWorkshopEN");
                }

            }
            else if (_companyId == "12")
            {
                //lblPromo.Text = "MSIG";
                if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.MSIGWorkshopTH");
                }
                else
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.MSIGWorkshopEN");
                }
            }
            else if (_companyId == "16")
            {
                //lblPromo.Text = "AXA";
                if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.AXAWorkshopTH");
                }
                else
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.AXAWorkshopEN");
                }
            }
            else if (_companyId == "29")
            {
                //lblPromo.Text = "LMG Insurance";
                if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.LMGWorkshopTH");
                }
                else
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.LMGWorkshopEN");
                }
            }
            else if (_companyId == "31")
            {
                //lblPromo.Text = "Chartis";
                if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ChartisWorkshopTH");
                }
                else
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ChartisWorkshopEN");
                }
            }
            else if (_companyId == "32")
            {
                //lblPromo.Text = "Bangkok Insurance";
                if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.BKIWorkshopTH");
                }
                else
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.BKIWorkshopEN");
                }
            }
            else if (_companyId == "33")
            {
                //lblPromo.Text = "MTI Insurance";
                if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.MTIWorkshopTH");
                }
                else
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.MTIWorkshopEN");
                }
            }
            else if (_companyId == "35")
            {
                //lblPromo.Text = "KPI Insurance";
                if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.KPIWorkshopTH");
                }
                else
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.KPIWorkshopTH");
                }
            }
            else if (_companyId == "39")
            {
                //lblPromo.Text = "KPI Insurance";
                if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.MittareWorkshopTH");
                }
                else
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.MittareWorkshopEN");
                }
            }
            else if (_companyId == "41")
            {
                //lblPromo.Text = "Kurnia Insurance";
                if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.KurniaWorkShopTH");
                }
                else
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.KurniaWorkShopTH");
                }
            }
            else if (_companyId == "43")
            {
                //lblPromo.Text = "TMS Insurance";
                if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.SMKWorkShopTH");
                }
                else
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.SMKWorkShopEN");
                }
            }
            else if (_companyId == "46")
            {
                //lblPromo.Text = "TMS Insurance";
                if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.TokioWorkShopTH");
                }
                else
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.TokioWorkShopEN");
                }
            }
            else if (_companyId == "58")
            {
                //lblPromo.Text = "TMS Insurance";
                if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ThaivivatWorkshopTH");
                }
                else
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ThaivivatWorkshopEN");
                }
            }
            else if (_companyId == "66")
            {
                //lblPromo.Text = "Dhipaya Insurance";
                if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.DhipayaWorkshopTH");
                }
                else
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.DhipayaWorkshopEN");
                }
            }
            else if (_companyId == "67")
            {
                //lblPromo.Text = "Deves Insurance";
                if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.DevesWorkshopTH");
                }
                else
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.DevesWorkshopEN");
                }
            }
            else if (_companyId == "68")
            {
                //lblPromo.Text = "Thaisri Insurance";
                if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ThaiSriWorkshopTH");
                }
                else
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ThaiSriWorkshopEN");
                }
            }
            else if (_companyId == "69")
            {
                //lblPromo.Text = "Thaisri Insurance";
                if (HttpContext.Current.Session["Language"].ToString() == "th-TH")
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.AssetsWorkshopTH");
                }
                else
                {
                    hplnkWorkshop.NavigateUrl = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.AssetsWorkshopEN");
                }
            }
            //END GARAGE
        }

    }

    protected void gvCarResult_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("MySelect"))
        {
            if (e.CommandArgument != null)
            {
                Int64 _ResultId = 0;
                Int64 _CECarId = 0;
                Int64 _Result = 0;
                _ResultId = Convert.ToInt64(e.CommandArgument);
                _CECarId = Convert.ToInt64(txtCarId.Text);
                _Result = InsertSelectItem(_CECarId, _ResultId);
                if (_Result > 0)
                {
                    string _strParameters = "leadid=" + txtAgentLeadId.Text.Trim() + "&calltype=" + txtCallTypeId.Text.Trim();
                    _strParameters += "&custid=" + txtCustomerId.Text.Trim() + "&carid=" + txtCarId.Text.Trim();
                    Response.Redirect("ViewCINoMatchFound.aspx?" + _strParameters.ToString());
                }
            }
        }
    }

    private void setControlVisible()
    {
        if (ddlNamedDrivers.Enabled == false)
        {
            trNamedDriver.Visible = false;
        }
        else
        {
            trNamedDriver.Visible = true;
        }

        if (ddlDriver1DOBDay.Enabled == false)
        {
            trDriverFirstDOB.Visible = false;
        }
        else
        {
            trDriverFirstDOB.Visible = true;
        }

        if (ddlDriver2DOBDay.Enabled == false)
        {
            trDriverTwoDOB.Visible = false;
        }
        else
        {
            trDriverTwoDOB.Visible = true;
        }

        if (ddlCTPL.Enabled == false)
        {
            trIsCTPL.Visible = false;
        }
        else
        {
            trIsCTPL.Visible = true;
        }

        if (ddlModification.Enabled == false)
        {
            trModification.Visible = false;
        }
        else
        {
            trModification.Visible = true;
        }
        if (txtAccModAmount.Enabled == false)
        {
            trModificationAmount.Visible = false;
        }
        else
        {
            trModificationAmount.Visible = true;
        }
        if (ddlProvinceRegistration.Enabled == false)
        {
            trProvinceRegistration.Visible = false;
        }
        else
        {
            trProvinceRegistration.Visible = true;
        }
        if (ddlAnyClaim.Enabled == false)
        {
            trIsClaim.Visible = false;
        }
        else
        {
            trIsClaim.Visible = true;
        }
        if (ddlNCB.Enabled == false)
        {
            trNCB.Visible = false;
        }
        else
        {
            trNCB.Visible = true;
        }

        if (ddlDeduct.Enabled == false)
        {
            trDEC.Visible = false;
        }
        else
        {
            trDEC.Visible = true;
        }
    }

    protected void gvCarResult_SelectedIndexChanged(object sender, EventArgs e)
    {
        txtSelectedResultId.Text = "0";
        txtSelectedProviderId.Text = "0";
        if (gvCarResult.Rows.Count > 0)
        {
            if (gvCarResult.SelectedIndex >= 0)
            {
                GridViewRow row = gvCarResult.SelectedRow;
                txtSelectedResultId.Text = gvCarResult.SelectedDataKey[0].ToString();
                txtSelectedProviderId.Text = gvCarResult.SelectedDataKey[1].ToString();
            }
        }
    }

    #region Save & Update

    private bool Save(Int64 UserID)
    {
        Int64 _carresult = 0;
        Int64 _policyresult = 0;

        CarDetailTH _car = new CarDetailTH();
        CarDetailTHDB _cardb = new CarDetailTHDB();

        CarUserProfileDB _profiledb = new CarUserProfileDB();
        CarUserProfile _profile = new CarUserProfile();

        CarUserContact _contact = new CarUserContact();
        CarUserContactDB _contactdb = new CarUserContactDB();

        if (txtCarId.Text != string.Empty && txtCarId.Text != "0")
        {
            _car = _cardb.GetCar(Convert.ToInt64(txtCarId.Text.Trim()), 0);
            if (lblRenewalStatus.Text == "1" || lblRenewalStatus.Text == "2")
            {
                _car.Info4 = "RENEWAL-UPDATE" + lblRenewalStatus.Text;
            }
            else
            {
                _car.Info4 = "UPDATE";
            }
        }
        else
        {
            if (lblRenewalStatus.Text == "1" || lblRenewalStatus.Text == "2")
            {
                _car.Info4 = "RENEWAL-NEW" + lblRenewalStatus.Text;
            }
            else
            {
                _car.Info4 = "NEW";
            }
        }

        if (_car == null)
        {
            _car = new CarDetailTH();
            if (lblRenewalStatus.Text == "1" || lblRenewalStatus.Text == "2")
            {
                _car.Info4 = "RENEWAL-NEW" + lblRenewalStatus.Text;
            }
            else
            {
                _car.Info4 = "NEW";
            }
        }

        if (UserID > 0)
        {
            _profile = _profiledb.GetProfile(UserID);
            _contact = _contactdb.GetContact(UserID);
            if (_profile != null && _contact != null)
            {
                _car.Info5 = _contact.Email;
                _car.Info6 = _contact.Mobile;
                _car.Info7 = _profile.SurName;
                if (_profile.FirstName.Trim().Length > 0)
                {
                    _car.Info8 = _profile.FirstName;//txtFirstName.Text.Trim();
                }
                _car.Info9 = _profile.Gender.ToString(); //ddlGender.GetGender();
                _car.Info10 = _profile.DOB.ToString("dd-MMM-yyyy"); //usrDOB.GetDate().ToString("dd-MMM-yyyy");
                _car.Info11 = _profile.Occupation.ToString();// ddlOccupation.GetOccupation();
                _car.Info12 = _profile.JobNature;//ddlJobNature.GetJobNature();
                _car.Info13 = _profile.MaritalStatus.ToString();//ddlMaritalStatus.GetMaritalStatus();
                _car.Info14 = "0"; //ddlYearDriveSg.Text;
                _car.Info15 = _profile.Salutation;//ddlSalutation.GetSalutation();
                _profile = null;
                _contact = null;
            }
        }

        _car.ManufactYear = Convert.ToInt32(ddlCarYear.Text);

        if (Session[General.UserId] != "0")
        {
            _car.Info2 = Session[General.UserId].ToString();
            _car.Info3 = dateTimeNow.ToString();
        }

        _car.CarMakeName = ddlCarMake.Text;//Convert.ToInt32(txtCarMakeId.Text);
        _car.MakeModelDesc = ddlCarMake.SelectedItem.Text + " " + ddlModelBodyCCDoor.SelectedItem.Text;

        bool IsOther = false;
        string[] _tempDesc = ddlModelBodyCCDoor.Text.Split(' ');
        if (_tempDesc.Length == 5)
        {
            _car.CarModelName = _tempDesc[0];
            _car.Body = _tempDesc[1];
            _car.CC = Convert.ToInt32(_tempDesc[2].Substring(0, _tempDesc[2].Length - 2));
            _car.Door = Convert.ToInt32(_tempDesc[3]);
        }
        else if (_tempDesc.Length == 6)
        {
            _car.CarModelName = _tempDesc[0] + " " + _tempDesc[1];
            _car.Body = _tempDesc[2];
            _car.CC = Convert.ToInt32(_tempDesc[3].Substring(0, _tempDesc[3].Length - 2));
            _car.Door = Convert.ToInt32(_tempDesc[4]);
        }
        else if (_tempDesc.Length == 7)
        {
            _car.CarModelName = _tempDesc[0] + " " + _tempDesc[1] + " " + _tempDesc[2];
            _car.Body = _tempDesc[3];
            _car.CC = Convert.ToInt32(_tempDesc[4].Substring(0, _tempDesc[4].Length - 2));
            _car.Door = Convert.ToInt32(_tempDesc[5]);
        }
        else if (ddlModelBodyCCDoor.Text == "-2")
        {
          
            IsOther = true;
            _car.CarMakeName = txtOtherCarMake.Text.Trim();
            _car.CarModelName = txtOtherCarModel.Text.Trim();
            _car.Body = ddlOtherCarBody.Text;
            _car.CC = Convert.ToInt32(txtCcCar.Text.Trim());
            _car.Door = Convert.ToInt32(ddlOtherCarDoor.Text);

            _car.MakeModelDesc = txtOtherCarMake.Text.Trim() + " " + txtOtherCarModel.Text.Trim() + " " + ddlOtherCarBody.Text + " " + txtCcCar.Text.Trim() + " cc " + ddlOtherCarDoor.Text + " doors";
        }
        //Yui@06062014
        _car.GroupNo = 0; //Convert.ToInt32(txtGroupNo.Text);
        _car.Info2 = ""; //lblCarVehicleType.Text;
        _car.Info3 = "";
        //if (lblCarVehicleType.Text == "PS" || lblCarVehicleType.Text == "SV" || lblCarVehicleType.Text == "")
        //{
        //    _car.Info3 = ddlVehicleType.Text;
        //}
        //else if (lblCarVehicleType.Text == "LC")
        //{
        //    if (ddlVehicleType.Text == "110")
        //    {
        //        _car.Info3 = "210";
        //    }
        //    else if (ddlVehicleType.Text == "120")
        //    {
        //        _car.Info3 = "220";
        //    }
        //}
        //else if (lblCarVehicleType.Text == "PU")
        //{
        //    if (ddlVehicleType.Text == "110")
        //    {
        //        _car.Info3 = "320";
        //    }
        //    else if (ddlVehicleType.Text == "120")
        //    {
        //        _car.Info3 = "340"; //Disabled, No Packages
        //    }
        //}
        
        _car.Status = true;
        _car.RefCEUserId = UserID;
        _car.ViewedDetailId = 0;// Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
        _car.CurrentStep = 1;
        _car.TotalStep = 4;
        _car.Info1 = ddlCurrentInsurer.Text; //Current Insurer ID

        _carresult = _cardb.Insert(_car);
      
        _cardb.UpdateCarOther(_carresult, IsOther);

        _car = null;
        _cardb = null;
       

        if (_carresult > 0)
        {
            DeleteCISelectedItem(_carresult);
            if (txtCallTypeId.Text == "103")
            {
                UpdateCustomerId(_carresult, Convert.ToInt64(txtAgentLeadId.Text), 0, UserID, Convert.ToInt64(txtCallTypeId.Text));
            }
            else
            {
                UpdateCustomerId(_carresult, Convert.ToInt64(txtAgentLeadId.Text), Convert.ToInt64(txtCallMeId.Text), UserID, Convert.ToInt64(txtCallTypeId.Text));
            }
        }
        else
        {
            lblMessage.Text = "Insert error!";
        }
      
        if (_carresult > 0)
        {
            txtCarId.Text = _carresult.ToString();
            //CAR POLICY DETAILS
            CarPolicy _carpolicy = new CarPolicy();
            CarPolicyDB _carpolicydb = new CarPolicyDB();
            Int64 _carId = Convert.ToInt64(txtCarId.Text);

            Int64 _carpolicyid = 0;

            if (txtCECarPolicyId.Text != string.Empty && txtCECarPolicyId.Text != "0")
            {
                _carpolicyid = Convert.ToInt64(txtCECarPolicyId.Text);
                _carpolicy.CECarPolicyId = _carpolicyid;
                
                _carpolicy.Info5 = "UPDATE";
                
            }
            else
            {
                
                _carpolicy.Info4 = "NEW";
              
            }

            _carpolicy.Info8 = lblTESCO200.Text;

            lblMessage.Text = "";
            if (Session[General.UserId] != null)
            {
                _carpolicy.Info2 = Session[General.UserId].ToString();
                _carpolicy.Info3 = dateTimeNow.ToString();
            }

            if (lblRenewalStatus.Text == "1" || lblRenewalStatus.Text == "2")
            {
                _carpolicy.Info6 = lblLastYearCarID.Text;
                _carpolicy.Info7 = lblLastYearRefNo.Text;
            }

            _carpolicy.CECarId = _carId;
            _carpolicy.InsuranceType = Convert.ToInt32(ddlInsuranceType.Text);
            _carpolicy.GarageType = Convert.ToInt32(ddlGarageType.Text);

            //Yui@06062014
            _carpolicy.VehicleType = 110; //Convert.ToInt32(ddlVehicleType.Text);
            _carpolicy.SumInsured = 0; // Convert.ToInt32(txtSumInsured.Text);

            _carpolicy.ProvinceRegistration = ddlProvinceRegistration.Text;
            _carpolicy.UseOfVehicle = "N/A";//ddlUseOfVehicle.Text;
            string strDate = ddlCoverageComDate.Text;
            int _iDay = Convert.ToInt32(strDate.Substring(0, 2));
            int _iMonth = Convert.ToInt32(strDate.Substring(2, 2));
            int _iYear = Convert.ToInt32(strDate.Substring(4, 4));
            _carpolicy.CoverageCommenceDate = new DateTime(_iYear, _iMonth, _iDay);
            _carpolicy.IsRedPlate = false; //rdoYesRedPlate.Checked;

            if (ddlModification.Text == "1")
            {
                _carpolicy.IsAddAccMod = true;
            }
            else
            {
                _carpolicy.IsAddAccMod = false;
            }

            if (_carpolicy.IsAddAccMod == true)
            {
                _carpolicy.AddAccModAmount = Convert.ToInt32(txtAccModAmount.Text);
            }
            else
            {
                _carpolicy.AddAccModAmount = 0;
            }
            _carpolicy.NCDPercent = Convert.ToInt32(ddlNCB.Text);
            if (ddlAnyClaim.Text == "1")
            {
                _carpolicy.IsClaimLastYear = true;
            }
            else
            {
                _carpolicy.IsClaimLastYear = false;
            }
            if (ddlCTPL.Text == "1")
            {
                _carpolicy.IsCTPL = true;
            }
            else
            {
                _carpolicy.IsCTPL = false;
            }

            if (ddlNamedDrivers.Text != "0")
            {
                _carpolicy.IsAddDriver = true;
                _carpolicy.NoOfDriver = Convert.ToInt16(ddlNamedDrivers.Text);
            }
            else
            {
                _carpolicy.IsAddDriver = false;
                _carpolicy.NoOfDriver = 0;
            }
            
            _carpolicy.Deductible = Convert.ToInt16(ddlDeduct.SelectedValue);
            _carpolicy.CurrentInsurer = ddlCurrentInsurer.SelectedItem.Text;
            _carpolicy.RefCEUserId = UserID;
            
            _carpolicy.Status = true;
            _carpolicy.CurrentStep = 2;

            //This is for GG Web
            _carpolicy.NInfo5 = 1;
            //Yui@06062014
            _carpolicy.Product = ddlModelBodyCCDoor.Text;

            _policyresult = _carpolicydb.Insert(_carpolicy);
            if (_policyresult > 0)
            {
                txtCECarPolicyId.Text = _policyresult.ToString();

                lblMessage.Text += "<br>Car policy saved successfully!";
                lblMessage.ForeColor = System.Drawing.Color.Blue;
            }
            else
            {
                lblMessage.Text = "Car policy did not save successfully!";
                lblMessage.ForeColor = System.Drawing.Color.Red;
                return false;
            }

            CarDriver _cardriver = new CarDriver();
            CarDriverDB _cardriverdb = new CarDriverDB();

            if (ddlNamedDrivers.Text != "0")
            {
                int _drivercount = Convert.ToInt32(ddlNamedDrivers.Text);
                int _insertcount = 0;
                _cardriverdb.UpdateAllStatus(_carId, UserID);

                for (int i = 1; i <= _drivercount; i++)
                {
                    _cardriver.StepId = 1;
                    _cardriver.RerCEUserId = UserID;
                    _cardriver.CECarId = _carId;
                    if (i == 1)
                    {
                        _cardriver.CarDriverId = Convert.ToInt64(txtDriverId1.Text);
                        DateTime _dtDOB1 = new DateTime(Convert.ToInt32(ddlDriver1DOBYear.Text), Convert.ToInt32(ddlDriver1DOBMonth.Text), Convert.ToInt32(ddlDriver1DOBDay.Text));
                        _cardriver.DOB = _dtDOB1;
                        _cardriver.Status = "Active";
                    }
                    else if (i == 2)
                    {
                        _cardriver.CarDriverId = Convert.ToInt64(txtDriverId2.Text);
                        DateTime _dtDOB2 = new DateTime(Convert.ToInt32(ddlDriver2DOBYear.Text), Convert.ToInt32(ddlDriver2DOBMonth.Text), Convert.ToInt32(ddlDriver2DOBDay.Text));
                        _cardriver.DOB = _dtDOB2;
                        _cardriver.Status = "Active";
                    }

                    _cardriver.ViewedDetailId = 0;//Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                    if (_cardriverdb.Insert(_cardriver) > 0)
                    {
                        _insertcount++;
                    }
                }

                _cardriverdb = null;
                _cardriver = null;

                if (_insertcount == _drivercount)
                {
                    lblMessage.Text += "<br>All drivers are successfully saved!";
                    lblMessage.ForeColor = System.Drawing.Color.Blue;
                }
                else
                {
                    lblMessage.Text += "<br>All drivers are did not saved!";
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                    return false;
                }
            }
            else
            {
                _cardriverdb.UpdateAllStatus(_carId, UserID);
            }

            _carpolicy = null;
            _carpolicydb = null;
        }

        if (Request.QueryString["ismobile"] != null)
        {
            //First time from Mobile
            //tblcardetailth.binfo2 for keeping the status that the record was already update (for mobile only).
            Int64 _carId = Convert.ToInt64(txtCarId.Text);
            MyDatabase _myDb = new MyDatabase();
            int runVal = _myDb.ExecuteNonSqlStatement(@"UPDATE tblcardetailth SET binfo2 = 1 
                WHERE carid = " + _carId.ToString());
        }

        return _policyresult > 0;
    }

    private Int64 UpdateProfile(Int64 UserId)
    {
        Int64 _retValue = 0;

        if (UserId != 0)
        {
            _account = new CarUserAccount();
            _accountdb = new CarUserAccountDB();

            _profile = new CarUserProfile();
            _profiledb = new CarUserProfileDB();

            _contact = new CarUserContact();
            _contactdb = new CarUserContactDB();

            _account = _accountdb.GetAccount(UserId);
            _profile = _profiledb.GetProfile(UserId);
            _contact = _contactdb.GetContact(UserId);

            if (_account != null)
            {
                if (_account.UserTypeId == 1001)
                {
                    _account.Email = txtEmailAddress.Text;
                    _account.AuthCode = txtMobileNo.Text;
                    _account.RefCEUserID = Convert.ToInt64(txtAgentId.Text);
                    _account.Status = true;
                    _retValue = _accountdb.Insert(_account);
                }
                else
                {
                    _retValue = _account.CEID;
                }
            }

            if (_retValue > 0 && _profile != null)
            {
                #region Update Profile

                _profile.Salutation = ""; // ddlSalutation.GetSalutation();
                _profile.FirstName = txtFirstName.Text;
                _profile.SurName = txtLastName.Text;
                DateTime _dtDOB = new DateTime(Convert.ToInt32(ddlDOBYear.Text), Convert.ToInt32(ddlDOBMonth.Text), Convert.ToInt32(ddlDOBDay.Text));
                _profile.DOB = _dtDOB;
                _profile.Gender = Convert.ToChar(ddlGender.Text);

                _profile.MaritalStatus = -1;// Convert.ToInt32(ddlMaritalStatus.GetMaritalStatus());
                _profile.JobNature = "";// ddlJobNature.GetJobNature();
                _profile.Occupation = Convert.ToInt32(ddlOccupation.Text);
                _profile.YearDriveSg = 0;//Convert.ToInt16(ddlYearDriveSg.Text);
                _profile.Status = "Complete";

                _retValue = _profiledb.Insert(_profile);

                if (_retValue > 0 && _contact != null)
                {
                    if (_account.UserTypeId == 1001)
                    {
                        _contact.Email = txtEmailAddress.Text;
                    }
                    _contact.Mobile = txtMobileNo.Text;
                    _contact.Status = true;

                    _retValue = _contactdb.Insert(_contact);
                }
                else
                {
                    _retValue = 0;
                }

                if (_retValue > 0)
                {
                    _retValue = UserId;
                }
                else
                {
                    _retValue = 0;
                }

                _profile = null;
                _contact = null;
                #endregion
            }
        }
        else
        {
            _retValue = SaveNewCustomer();
            UserId = _retValue;
        }

        return _retValue;
    }

    private Int64 SaveNewCustomer()
    {
        #region New Customer
        Int64 _retVal = 0;


        CarUserAccount _useraccount = new CarUserAccount();
        CarUserAccountDB _useraccountdb = new CarUserAccountDB();

        CarUserProfile _userprofile = new CarUserProfile();
        CarUserProfileDB _userprofiledb = new CarUserProfileDB();
        CarUserContact _contact = new CarUserContact();
        CarUserContactDB _contactdb = new CarUserContactDB();

        long _result = -1;
        _useraccount.Email = txtEmailAddress.Text.ToLower();
        string _authcode = txtMobileNo.Text;

        _useraccount.AuthCode = _authcode;
        _useraccount.UserId = "CEUSERIDBYAGENT";
        _useraccount.UserTypeId = Convert.ToInt32(CE.Global.CEUserType.Customer);
        if (Session[General.UserCampaign] != null && Session[General.UserCampaign].ToString() == "1001")
        {
            _useraccount.UserTypeId = 1001;// Convert.ToInt32(Session[General.UserCampaign].ToString()); 
        }
        _useraccount.IsAcceptTC = false;
        _useraccount.Status = true;
        _useraccount.RefCEUserID = Convert.ToInt64(Session[General.UserId].ToString());
        _result = _useraccountdb.Insert(_useraccount);
        _useraccount.CEID = _result;
        _retVal = _useraccount.CEID;

        if (_result > 0)
        {
            txtCustomerId.Text = _result.ToString();
            lblRedirectCustomerId.Text = txtCustomerId.Text;
            _userprofile.Salutation = ""; //ddlSalutation.GetSalutation();
            _userprofile.FirstName = Server.HtmlEncode(txtFirstName.Text);
            _userprofile.SurName = Server.HtmlEncode(txtLastName.Text);

            DateTime _dtDOB = new DateTime(1900, 1, 1);
            _dtDOB = new DateTime(Convert.ToInt32(ddlDOBYear.Text), Convert.ToInt32(ddlDOBMonth.Text), Convert.ToInt32(ddlDOBDay.Text));
            _userprofile.DOB = _dtDOB;
            _userprofile.Gender = Convert.ToChar(ddlGender.Text);
            _userprofile.Occupation = Convert.ToInt32(ddlOccupation.Text);
            _userprofile.Status = "Complete";
            _userprofile.RefCEUserId = Convert.ToInt64(txtCustomerId.Text);
            _userprofile.IsAcceptTC = true;
            _result = _userprofiledb.Insert(_userprofile);

            _contact.Email = _useraccount.Email;
            _contact.Mobile = txtMobileNo.Text;
            _contact.Status = true;
            _contact.RefCEUserId = _useraccount.CEID;
            _result = _contactdb.Insert(_contact);
        }

        return _retVal;

        #endregion
    }

    private bool CheckClaimValue()
    {
        bool ClaimValue = true;
        return ClaimValue;
    }

    public Int64 DeleteCISelectedItem(Int64 CarId)
    {
        MyDatabase _db = new MyDatabase();
        Int64 _result = -1;
        string _spName = "sprocCXCRMDeleteCarInsuranceSelectedItemByCarId";

        SortedList _sPara = new SortedList();

        #region Parameter
        _sPara.Add("@CarId", CarId);
        #endregion

        _result = _db.ExecuteSP(_spName, _sPara);

        return _result;
    }

    public Int64 UpdateCallMeId(Int64 CarId, Int64 CallMeId)
    {
        MyDatabase _db = new MyDatabase();
        Int64 _result = -1;
        string _spName = "sprocCXCRMUpdateCallMeIdSingleItemByCarId";

        SortedList _sPara = new SortedList();

        #region Parameter
        _sPara.Add("@CarId", CarId);
        _sPara.Add("@CallMeId", CallMeId);
        #endregion

        _result = _db.ExecuteSP(_spName, _sPara);

        return _result;
    }

    public Int64 UpdateCustomerId(Int64 CarId, Int64 LeadId, Int64 CallMeId, Int64 CustomerId, Int64 CallTypeId)
    {
        MyDatabase _db = new MyDatabase();
        Int64 _result = -1;
        string _spName = "sprocCXCRMCustomerIdUpdateSingleItemByLeadId";

        SortedList _sPara = new SortedList();

        #region Parameter
        _sPara.Add("@CarId", CarId);
        _sPara.Add("@LeadId", LeadId);
        _sPara.Add("@CallMeId", CallMeId);
        _sPara.Add("@CustomerId", CustomerId);
        _sPara.Add("@CallTypeId", CallTypeId);
        #endregion

        _result = _db.ExecuteSP(_spName, _sPara);

        return _result;
    }

    public Int64 InsertSelectItem(Int64 CarId, Int64 CarResultId)
    {
        MyDatabase _db = new MyDatabase();
        Int64 _result = -1;
        string _spName = "sprocCXCRMCallMeResultSelectItemInsertUpdateSingleItem";

        SortedList _sPara = new SortedList();

        #region Parameter
        _sPara.Add("@CarId", CarId);
        _sPara.Add("@CarResultId", CarResultId);
        #endregion

        _result = _db.ExecuteSP(_spName, _sPara);

        return _result;
    }

    #endregion

    #region "testShowDetail"

    private void ShowCustomerDetail(CarUserAccount UserAccount)
    {
        _profile = new CarUserProfile();
        _profiledb = new CarUserProfileDB();
        _contact = new CarUserContact();
        _contactdb = new CarUserContactDB();

        _profile = _profiledb.GetProfile(UserAccount.CEID);
        _profiledb = null;

        btnNonGGQuotation.Visible = false;

        if (_profile != null)
        {
            txtFirstName.Text = _profile.FirstName;
            txtLastName.Text = _profile.SurName;

            ddlOccupation.Text = _profile.Occupation.ToString();
            ddlGender.Text = _profile.Gender.ToString();

            ddlDOBDay.Text = _profile.DOB.Day.ToString("00");
            ddlDOBMonth.Text = _profile.DOB.Month.ToString("00");
            ddlDOBYear.Text = _profile.DOB.Year.ToString("0000");

            if (UserAccount.Status == true)
            {
                btnNonGGQuotation.Visible = true;
            }
            else
            {
                btnNonGGQuotation.Visible = false;
            }

            _contact = _contactdb.GetContact(UserAccount.CEID);
            if (_contact != null)
            {
                string strMobile = _contact.Mobile;
                txtMobileNo.Text = strMobile;

                if (UserAccount.Status == true)
                {
                    txtEmailAddress.Text = _account.Email;
                }
                else
                {
                    txtEmailAddress.Text = "support@gluaygluay.com";
                }

                if (UserAccount.UserTypeId == 1001)
                {
                    txtEmailAddress.ReadOnly = false;

                    CultureInfo ci = new CultureInfo("th-TH");
                    if (lblLangOption.Text == "2")
                    {
                        ci = new CultureInfo("en-US");
                    }

                    DateTime dtNow = dateTimeNow.AddDays(60);
                    for (int i = 1; i < 60; i++)
                    {
                        DateTime dtTemp = dtNow.AddDays(i);
                        string strDate = dtTemp.Date.Day.ToString("00") + dtTemp.Date.Month.ToString("00") + dtTemp.Date.Year.ToString("0000");
                        ddlCoverageComDate.Items.Add(new ListItem(dtTemp.ToString("dd/MMMM/yyyy", ci), strDate));
                    }
                }
                else
                {
                    txtEmailAddress.ReadOnly = _account.Status;
                }

             
            }

            //Disable DOB, Gender and Year of Driving Exp Sg

            _profile = null;
        }
    }

    #endregion

    #region Call Status

    private int GetNoOfHoliday(int NoOfDay)
    {
        int _retValue = 0;
        MyDatabase _db = new MyDatabase();
        string spName = "[sprocCXCRMAgentCalenderGetEventsCount]";
        SortedList paraList = new SortedList();
        DateTime startDate = dateTimeNow;
        DateTime endDate = dateTimeNow.AddDays(NoOfDay);
        paraList.Add("@StartDate", startDate.ToString("yyyyMMdd"));
        paraList.Add("@EndDate", endDate.ToString("yyyyMMdd"));
        object eventCount = _db.ExecuteScalarSP(spName, paraList);
        if (eventCount != null)
        {
            _retValue = Convert.ToInt32(eventCount);
        }
        return _retValue;
    }

    private int GetNoOfCallBackDay()
    {
        int _noOfDays = 4;

        if (Session[General.IsRenewalAgent].ToString() == "1")
        {
            _noOfDays = 21;
        }

        _noOfDays = _noOfDays + GetNoOfHoliday(_noOfDays);

        DateTime chkDate = dateTimeNow.AddDays(_noOfDays);

        if (chkDate.Date.DayOfWeek == DayOfWeek.Saturday)
        {
            _noOfDays += 3;
        }
        else if (chkDate.Date.DayOfWeek == DayOfWeek.Sunday)
        {
            _noOfDays += 2;
        }

        return _noOfDays;
    }

    protected void csvTargetDate_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (rdoCallBack.Checked || trCallBack1.Visible == true)
        {
            int _noOfDays = GetNoOfCallBackDay();

            //string _strTargetDateTime = ddlTDay.Text + "/" + ddlTMonth.SelectedItem.Text + "/" + ddlTYear.Text + " " + ddlTHour.Text + ":" + ddlTMin.Text;
            string _strTargetDateTime = txtTargetDate.Text + " " + ddlTHour.Text + ":" + ddlTMin.Text;

            DateTime _dtTargetDateTime = dateTimeNow;

            DateTime _dtLimitDateTime = dateTimeNow.Date.AddDays(_noOfDays);

            if (ddlCIMainCallStatus.Text == "7" && ddlCICallStatus.Text == "10")
            {
                _dtLimitDateTime = dateTimeNow.AddDays(60);
                //_strTargetDateTime = ddlTDay.Text + "/" + ddlTMonth.SelectedItem.Text + "/" + ddlTYear.Text;
                _strTargetDateTime = txtTargetDate.Text;
            }

            if (DateTime.TryParse(_strTargetDateTime, out _dtTargetDateTime))
            {
                if (DateTime.Compare(dateTimeNow, _dtTargetDateTime) <= 0)
                {
                    txtCallBackDateTime.Text = _dtTargetDateTime.ToString("dd/MMM/yyyy hh:mm:ss tt");

                    if (ddlCIMainCallStatus.Text == "7" && ddlCICallStatus.Text == "10")
                    {
                        if (DateTime.Compare(_dtTargetDateTime, _dtLimitDateTime) > 0)
                        {
                            args.IsValid = true;
                        }
                        else
                        {
                            args.IsValid = false;
                            csvTargetDate.ErrorMessage = Resources.General.CommencementCheck;
                            lblCallStatusMessage.Text = Resources.General.CommencementCheck;
                        }
                    }
                    else
                    {
                        if (DateTime.Compare(_dtTargetDateTime, _dtLimitDateTime) <= 0)
                        {
                            args.IsValid = true;
                        }
                        else
                        {
                            args.IsValid = false;
                            csvTargetDate.ErrorMessage = Resources.General.CallBackDateTimeInvalid + " " + Resources.General.CallBackDaysLimitMessage;
                            lblCallStatusMessage.Text = Resources.General.CallBackDateTimeInvalid + " " + Resources.General.CallBackDaysLimitMessage;
                        }
                    }
                }
                else
                {
                    args.IsValid = false;
                    if (ddlCIMainCallStatus.Text == "7" && ddlCICallStatus.Text == "10")
                    {
                        csvTargetDate.ErrorMessage = Resources.General.CommencementCheck;
                        lblCallStatusMessage.Text = Resources.General.CommencementCheck;
                    }
                    else
                    {
                        csvTargetDate.ErrorMessage = Resources.General.CallBackDateTimeOlder;
                        lblCallStatusMessage.Text = Resources.General.CallBackDateTimeOlder;
                    }
                }
            }
            else
            {
                args.IsValid = false;
                txtCallBackDateTime.Text = "0";
                if (ddlCIMainCallStatus.Text == "7" && ddlCICallStatus.Text == "10")
                {
                    csvTargetDate.ErrorMessage = Resources.General.CommencementCheck;
                    lblCallStatusMessage.Text = Resources.General.CommencementCheck;
                }
                else
                {
                    csvTargetDate.ErrorMessage = Resources.General.CallBackDateTimeInvalid;
                    lblCallStatusMessage.Text = Resources.General.CallBackDateTimeInvalid;
                }
            }
        }
    }

    protected void ddlCIMainCallStatus_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlCIMainCallStatus.Items.Count > 0 && ddlCIMainCallStatus.SelectedIndex >= 0)
        {
            LoadCallStatusList(Convert.ToInt32(ddlCIMainCallStatus.Text));
            AddCustomerDetailAsRemark();
        }
    }

    private void LoadMainCallStatusList(int intType)
    {
        try
        {
            MyDatabase _db = new MyDatabase();
            string _strSQL = "Select MainCallStatusTypeID, " + Resources.DBTable.FieldName + " AS Description from tblCXCRMMainCallStatusType Where [Status] = 1 And [Type] = " + intType.ToString();

            DataTable _dtList = new DataTable("tblList");
            _dtList = _db.GetDataTable(_strSQL);
            ddlCIMainCallStatus.Items.Clear();
            if (_dtList != null && _dtList.Rows.Count > 0)
            {
                // lee @24/03/2015
                ddlCIMainCallStatus.DataSource = _dtList;
                ddlCIMainCallStatus.DataTextField = "Description";
                ddlCIMainCallStatus.DataValueField = "MainCallStatusTypeID";
                ddlCIMainCallStatus.DataBind();
                //for (int i = 0; i < _dtList.Rows.Count; i++)
                //{
                //    ddlCIMainCallStatus.Items.Add(new ListItem(_dtList.Rows[i]["Description"].ToString(), _dtList.Rows[i]["MainCallStatusTypeID"].ToString()));
                //}
            }
            //ddlCIMainCallStatus.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        }
        catch (Exception Ex)
        {
            lblCallSessionName.Text += "<br/><b style='color:red;'>" + Resources.General.ERROR + "</b>: at LoadMainCallStatusList()<br/>" + Ex.Message + "<br/><br/>" + Ex.StackTrace;
        }
    }

    private void LoadCallStatusList(int MainStatusID)
    {
        try
        {
            MyDatabase _db = new MyDatabase();
            string _strSQL = "Select CallStatusTypeID, " +
                                " '[' + CAST(StatusCode AS VARCHAR) + '] ' + " + Resources.DBTable.FieldName + " AS Description " +
                                " FROM tblCXCRMCallStatusType Where [Status] = 1 And [MainCallStatusTypeID] = " + MainStatusID.ToString();
            DataTable _dtList = new DataTable("tblList");
            _dtList = _db.GetDataTable(_strSQL);
            ddlCICallStatus.Items.Clear();
            if (_dtList != null && _dtList.Rows.Count > 0)
            {
                // lee @24/03/2015
                ddlCICallStatus.DataSource = _dtList;
                ddlCICallStatus.DataTextField = "Description";
                ddlCICallStatus.DataValueField = "CallStatusTypeID";
                ddlCICallStatus.DataBind();
                //for (int i = 0; i < _dtList.Rows.Count; i++)
                //{
                //    ddlCICallStatus.Items.Add(new ListItem(_dtList.Rows[i]["Description"].ToString(), _dtList.Rows[i]["CallStatusTypeID"].ToString()));
                //}
            }
            ddlCICallStatus.Items.Insert(0,new ListItem(Resources.CarInsurance.Select, "-1"));
        }
        catch (Exception Ex)
        {
            lblCallSessionName.Text += "<br/><b style='color:red;'>" + Resources.General.ERROR + "</b>: at LoadCallStatusList()<br/>" + Ex.Message + "<br/><br/>" + Ex.StackTrace;
        }
    }

    protected void btnCallStatus_Click(object sender, EventArgs e)
    {
        Int64 _carID = 0;
        if (!Int64.TryParse(txtCarId.Text, out _carID))
        {
            _carID = 0;

            lblCallStatusMessage.Text = "โปรดบันทึกรายละเอียดรถ!";
            return;
        }

        Page.Validate("callstatus");
        if (Page.IsValid)
        {
            Int64 _customerID = 0;

            if (!Int64.TryParse(txtCustomerId.Text, out _customerID))
            {
                lblRedirectCustomerId.Text = "0";
                _customerID = 0;
            }
            else
            {
                lblRedirectCustomerId.Text = _customerID.ToString();
            }

            CallStatus callstatus = new CallStatus();
            CallStatusDB callstatusdb = new CallStatusDB();

            //CallType IS NOT USING ACTUALLY BECAUSE OF DUPLICATE LEADID
            callstatus = callstatusdb.GetCallStatus(Convert.ToInt64(txtAgentLeadId.Text), Convert.ToInt32(txtCallTypeId.Text));

            if (callstatus == null)
            {
                callstatus = new CallStatus();
            }

            callstatus.CarId = _carID;
            if (Session[CE.Global.General.CarResultId] != null)
            {
                callstatus.CarResultId = Convert.ToInt64(Session[CE.Global.General.CarResultId].ToString());
            }
            callstatus.CustomerId = _customerID;
            callstatus.AgentId = Convert.ToInt64(txtAgentId.Text);

            callstatus.AgentLeadId = Convert.ToInt64(txtAgentLeadId.Text);
            if (rdoCallFinish.Checked || rdoCallNotBuy.Checked)
            {
                callstatus.CallFinishType = 1;
            }
            else if (rdoCallBack.Checked)
            {
                callstatus.CallBackDateTime = Convert.ToDateTime(txtCallBackDateTime.Text);
                callstatus.CallBackAgentID = Convert.ToInt64(ddlCBAgentList.Text);
                callstatus.CallFinishType = 2;
            }
            //else if (rdoFollowUp.Checked)
            //{
            //    callstatus.CallFinishType = 3;
            //}

            callstatus.MainCallStatusTypeID = Convert.ToInt32(ddlCIMainCallStatus.Text);

            callstatus.CallStatusTypeID = Convert.ToInt32(ddlCICallStatus.Text);
            callstatus.CallTypeId = Convert.ToInt32(txtCallTypeId.Text);
            callstatus.StartDateTime = Convert.ToDateTime(lblStartDateTime.Text);

            callstatus.Remark = Server.HtmlEncode(txtCallStatus.Text);
            callstatus.CXCRMId = callstatusdb.Insert(callstatus);

            if (callstatus.CXCRMId > 0)
            {
                //Invalid/Wrong Number
                //Update tblCEUser.IsReject
                if (ddlCICallStatus.Text == "2")
                {
                    if (txtEmailAddress.Text.Trim() != "") UnSubscribeUserList(txtEmailAddress.Text.Trim());
                }

                if (txtCXCRMId.Text.Length > 0 && txtCXCRMId.Text != "0")
                {
                    lblCallStatusMessage.Text = Resources.General.UPDATE + " " + dateTimeNow.ToString("dd/MMM/yyyy hh:mm:ss tt");
                }
                else
                {
                    txtCXCRMId.Text = callstatus.CXCRMId.ToString();
                    lblCallStatusMessage.Text = Resources.General.SUCCESS + " " + dateTimeNow.ToString("dd/MMM/yyyy hh:mm:ss tt");
                }

                lblCallDurationTimer.Visible = false;

                lblCallStatusMessage.Text += ", " + Resources.General.CallDuration + ": " + GetCallDuration();
                btnNext.Visible = true;
                btnCallStatus.Enabled = false;

                //*** Promotion 
                //28March2014
                if (rdoCallFinish.Checked || rdoCallNotBuy.Checked)
                {
                    if (hidPromotionId.Value != "")
                    {
                        PromotionGGDB objPro = new PromotionGGDB();
                        objPro.UpdateAgent(Convert.ToInt64(hidPromotionId.Value), Convert.ToInt64(txtCustomerId.Text));
                    }
                }
            }
            else
            {
                lblCallStatusMessage.Text = Resources.General.FAIL + " " + dateTimeNow.ToString("dd/MMM/yyyy hh:mm:ss tt");
            }
            callstatus = null;
            callstatusdb = null;

            if (txtCarId.Text == "0")
            {
                txtCarId.Text = String.Empty;
            }
            if (txtCustomerId.Text == "0")
            {
                txtCustomerId.Text = String.Empty;
            }
        }
        else
        {
            if (txtCarId.Text == "0")
            {
                txtCarId.Text = String.Empty;
            }
            if (txtCustomerId.Text == "0")
            {
                txtCustomerId.Text = String.Empty;
            }
            
        }
    }

    #region SaveReject_InvalidNumber

    private void UnSubscribeUserList(string EmailList)
    {
        try
        {
            MyDatabase _db = new MyDatabase();
            string _spName = "[sprocCXRejectEmailInsertUpdateSelectedItemList]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@EmailList", EmailList);
            _sPara.Add("@EDM", 2);
            _sPara.Add("@EDMType", "2.EDM - Unsubscribe Update");
            #endregion

            DataTable _dt = _db.GetDataTableBySP(_spName, _sPara);
        }
        catch (Exception)
        {
        }
    }

    #endregion

    protected void btnNext_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/SiteUserHome.aspx");
       
    }

    private string GetCallDuration()
    {
        DateTime _dtStartTime = Convert.ToDateTime(lblStartDateTime.Text);
        TimeSpan _duration = dateTimeNow - _dtStartTime;
        string _strMin = _duration.Minutes.ToString();
        string _strSec = _duration.Seconds.ToString();
        txtMinute.Text = _strMin;
        txtSecond.Text = _strSec;

        if (Convert.ToInt16(_strMin) < 10)
        {
            _strMin = "0" + _strMin;
        }

        if (Convert.ToInt16(_strSec) < 10)
        {
            _strSec = "0" + _strSec;
        }

        return _strMin + " : " + _strSec;
    }

    protected void rdoCallFinish_CheckedChanged(object sender, EventArgs e)
    {
        trCallBack1.Visible = false;
        trCallBack2.Visible = false;
        if (rdoCallNotBuy.Checked)
        {
            LoadMainCallStatusList(4);
        }
        else if (rdoCallFinish.Checked)
        {
            LoadMainCallStatusList(1);
        }
        else if (rdoCallBack.Checked)
        {
            trCallBack1.Visible = true;
            trCallBack2.Visible = true;

            LoadMainCallStatusList(2);
        }

        if (ddlCIMainCallStatus.Items.Count > 0)
        {
            ddlCIMainCallStatus.SelectedIndex = 0;
            ddlCIMainCallStatus_SelectedIndexChanged(sender, e);
        }

    }


    private void AddCustomerDetailAsRemark()
    {
        string _customerDetail = string.Empty;
        Int64 _customerID = 0;

        if (Int64.TryParse(txtCustomerId.Text, out _customerID))
        {
            if (_customerID == 0)
            {
                if (txtFirstName.Text.Trim().Length > 0)
                {
                    _customerDetail = txtFirstName.Text;

                    if (txtLastName.Text.Trim().Length > 0)
                    {
                        _customerDetail += txtLastName.Text;
                        _customerDetail = "[" + Resources.CarInsurance.FullName + ": " + _customerDetail + "]";
                    }
                }
                else if (txtLastName.Text.Trim().Length > 0)
                {
                    _customerDetail = txtLastName.Text;
                    _customerDetail = "[" + Resources.CarInsurance.LastName + ": " + _customerDetail + "]";
                }

                if (txtMobileNo.Text.Trim().Length > 0)
                {
                    if (_customerDetail.Length > 0)
                    {
                        _customerDetail += " [" + Resources.CarInsurance.MobileNo + ": " + txtMobileNo.Text + "]";
                    }
                    else
                    {
                        _customerDetail = "[" + Resources.CarInsurance.MobileNo + ": " + txtMobileNo.Text + "]";
                    }
                }

                if (txtEmailAddress.Text.Trim().Length > 0)
                {
                    if (_customerDetail.Length > 0)
                    {
                        _customerDetail += " [" + Resources.CarInsurance.EmailAddress + ": " + txtEmailAddress.Text + "]";
                    }
                    else
                    {
                        _customerDetail = "[" + Resources.CarInsurance.EmailAddress + ": " + txtEmailAddress.Text + "]";
                    }
                }
            }

            if (txtCallStatus.Text.Trim().Length == 0)
            {
                txtCallStatus.Text = _customerDetail + "\n\r";
            }

            lblCallStatusMessage.Text = _customerDetail;
        }
    }

    #endregion

 

}
